Archived

This topic is now archived and is closed to further replies.

Help with rpg beginning!!

This topic is 5153 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hey im new to this forum and im also new to C++.. but anyways, i just want to create something simple, not too hard.. its going to be an rpg BEGINNING... not the whole game.. anyways, ive got my code, and it compiles ok for a regular text rpg, but somethings wrong in it.. heres the code: /* 01 Main.cpp */ #include <iostream> main (void) { /* Variable declarations */ unsigned char Age; long StartEnergy; char CharacterType; /* Get the Information */ std::cout << "What is your character''s age?: "; std::cin >> Age; std::cout << "How much start energy?: "; std::cin >> StartEnergy; std::cout << "What is your character type?: "; std::cin >> CharacterType; /* Show the Information */ std::cout << "Your character is " << Age << " years old." << std::endl; std::cout << "Has " << StartEnergy << " of starting energy." << std::endl; std::cout << "And its type is " << CharacterType << "." << std::endl; return 0; } ok when i compile it, it opens up the command prompt ok, but the line "What is your character type?" appears on the same line as "ow much start energy?"... i dont want this to happen, each thing is supposed to appear on different lines.. another thing i was curious about is after you answer the last question, the program closes out immediately... is there any way i can keep the window open until the USER decides to close it?

Share this post


Link to post
Share on other sites
"\nHow much start energy?: ";

or
cout << endl << "How much"...

endl and "\n" are for a newline


Hope this helps,
Lord Hen

"I am free of all prejudices. I hate everyone equally." - W. C. Fields

[edited by - Lord Hen on December 2, 2008 2:32:49 AM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Poor newbs. Just kidding bro. Try adding something like:

cout << "What is your age?: ";
cin >> age;
cout << endl << "What is your favorite movie?: ";
etc..

That endl is an end line statement, the same as ''\n'' in C. That will make the ouput go to the next line of the console. Just luck!

Share this post


Link to post
Share on other sites
I guess you can do this to wait at the end of the program:

#include <conio.h>
...
getch();

There are probably problems with using that...
Anyone know of a way to do this better, and make it so the user cant just type stuff in, but only enter does something?

Lord Hen

"I am free of all prejudices. I hate everyone equally." - W. C. Fields

[edited by - Lord Hen on December 2, 2008 2:32:49 AM]

Share this post


Link to post
Share on other sites
to make things alittle simpler and clearer, below your include file, type:

using namespace std;

This will allow you to get rid of the std:: before cout, cin and the like.

Other than that, have fun!
Ad

Share this post


Link to post
Share on other sites
quote:
Original post by Anonymous Poster
That endl is an end line statement, the same as ''\n'' in C. That will make the ouput go to the next line of the console. Just luck!

std::endl is not equivalent to ''\n''. ''\n'' is the newline feed character. std::endl will insert a newline feed (and, depending on the OS, possible a carriage return ''\r'' as well), and also flush the I/O buffer (which can alternatively be done by inserting the flush object: std::cout << std::flush).

Hypothetically this is presumably somewhat slower, but of course, when dealing with console I/O this is not ever going to be noticeable. It is valuable to know, however, that endl will insert the newline sequence suitable to the OS the code is compiled for, as this will vary between platforms (Windows vs. *NIX, for example).

Share this post


Link to post
Share on other sites