Jump to content

Need A Program Challenge


Archerzz

Recommended Posts

  • Replies 60
  • Created
  • Last Reply

Top Posters In This Topic

std::cout <<"Hello World\n";

 

right?

 

 

Just wondering, I just began learning C++. dont bash me for being a n00b.

 

edit: so would this be a valid program?

#include <iostream>

void didit()
{
    std::cout <<"I did it\n";
}

main ()
{
     std::cout <<"Hello World\n";
     didit();
}

Edited by martymcfly

Share this post


Link to post
Share on other sites

ok

if i had this string

string moo = "Hello World"

 

if i wanted to print that i would type

 

cout << moo;

 

right?

508088[/snapback]

 

Ah, the old "Hello World" string.... The true sign of someone learning a new language :)

Share this post


Link to post
Share on other sites

ok, what I'm trying to do is write a program that will sing

99 bottles of beer, on the wall

99 bottles of beer

you take one down pass it around

98 bottles of beer on the wall

...

 

so far what all I have gotten is friggin strings undeclared anyone see what errors they are talking about?

 

#include <iostream>
#include <string>

int main()
{
   int n = 99;
   string S1 = " Bottles of beer";
   string S2 = ", On the wall";
   string S3 = "You take one down, pass it around";
   
   while ( n > 0)
   {
         cout << n << S1 << S2 << endl;
         cout << n << S1 << endl;
         cout << S3 << endl;
         n--;
   }
   cout << "No more bottles of beer on the wall!"
   return 0;
}

Share this post


Link to post
Share on other sites

ok, what I'm trying to do is write a program that will sing

99 bottles of beer, on the wall

99 bottles of beer

you take one down pass it around

98 bottles of beer on the wall

...

 

so far what all I have gotten is friggin strings undeclared anyone see what errors they are talking about?

 

#include <iostream>
#include <string>

int main()
{
   int n = 99;
   string S1(" Bottles of beer");
   string S2(", On the wall");
   string S3("You take one down, pass it around");
   
   while ( n > 0)
   {
         cout << n << S1 << S2 << endl;
         cout << n << S1 << endl;
         cout << S3 << endl;
         n--;
   }
   cout << "No more bottles of beer on the wall!"
   return 0;
}

508110[/snapback]

 

I just told you how to use strings, and it didn't involve brackets :lol:

 

string S1 = " Bottles of beer";

string S2 = ", On the wall";

string S3 = "You take one down, pass it around";

 

You need that using namespace std; thing too if you want to use "string"

 

You missed a ; on the cout before return 0; btw :)

Share this post


Link to post
Share on other sites

i noticed the bracket thing after i posted it I went and changed it shortley after but not soon enough :)

and that using namespace std; thing would fall under the catagory of nice to know sooner :lol: ok lets see how this works out now...

 

 

WOOOT it worked :D

Share this post


Link to post
Share on other sites

i noticed the bracket thing after i posted it I went and changed it shortley after but not soon enough :)

and that using namespace std; thing would fall under the catagory of nice to know sooner :lol: ok lets see how this works out now...

WOOOT it worked  :D

508116[/snapback]

 

haha. It's all good!

 

If uhm.. anyone wants to search BSD man pages for C functions and their documentation, like printf() ... I just installed a man page to HTML thing, which can be found at:

 

http://bone.bone.servebeer.com/cgi-bin/man.cgi

 

Stick "printf" in the topic box and be amazed!!

 

Quite neat. I'll probably use it anyway, saves me logging in via SSH all the time :lol:

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×
×
  • Create New...