Jump to content
Sign in to follow this  
Archerzz

Need A Program Challenge

Recommended Posts

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

I am definatly bookmarking that beast now I can learn what yit means

:thumbs-up:

Share this post


Link to post
Share on other sites

Might have to play about with it and see if I can get it to just show the programming manual pages though. :)

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...