Im using Dev cpp that came with the book but will switch to Visual C++ as soon as im done with the book (want all the example code to compile)
Tanks for the link. Reading it right now =)
Help with basic C++ question
string help(){ cout << "\n\tcommands:"; cout << "\nsystem commands\n"; cout << "/help -command list\n"; cout << "/quit -quit game\n"; cout << "\ngame commands\n"; cout << "look -room overview\n"; cout << "talk -talk to persons in the room\n"; system("PAUSE"); return 0;}
In all your functions except for main, the function declaration is saying that it will return a string object, so why are you returning an int?
Your functions' return values are strings, but they return an integer (return 0;). That's like writing "string foo = 0" and your compiler would complain about that. You will learn a way how to track this bug down later (try catch mechanism), don't worry about it yet.
Onto another point: you won't want to use "cin >> command" in this case. So to save you from some funny bugs, use this instead:
I added the cout << "> " << flush here to illustrate something. When your program starts you'll have this neat prompt where you can input something, e.g. "> help" then hit enter. This will work with your code. However, type "help me" or "help quit" and you'll get multiple prompts/answers, because cin always extracts single words. The getline(cin, command) function will not do this, but look at the input as a whole.
string command;while (true){ cout << "> " << flush; getline(cin, command); // quit app (breaks the while loop so code after it still gets executed) // this could be cleaning up allocated memory or just sayin good bye ;) if (command == "quit") break; // show help else if (command == "help") help(); // look around the room else if (command == "look") look(); // Je ne parle francais? else cout << "Pardon?" << endl;}
I added the cout << "> " << flush here to illustrate something. When your program starts you'll have this neat prompt where you can input something, e.g. "> help" then hit enter. This will work with your code. However, type "help me" or "help quit" and you'll get multiple prompts/answers, because cin always extracts single words. The getline(cin, command) function will not do this, but look at the input as a whole.
Your functions behavior, look and help have a return type string, yet you return 0 which is not a string. If you don't want to return anything replace the return type with void and get rid of the return 0;
void behavior() //people behavior{ cout << "Hmmm...\n"; system("PAUSE");}
Whoops, looks like I was 20 minutes late. That's what happens when you open multiple topics simultanously and answer one by one without refreshing first :)
Im using a vector to store the curent people in the room.
Any suggestions on a way to give each person different conversations and new unlockable topics to talk about?
I want it to run like this:
> talk
TALK TO: >Ned
Ned: Whats up?
> (different topics to choose from)
Any suggestions on a way to give each person different conversations and new unlockable topics to talk about?
I want it to run like this:
> talk
TALK TO: >Ned
Ned: Whats up?
> (different topics to choose from)
Quote:Original post by Basse85
Any suggestions on a way to give each person different conversations and new unlockable topics to talk about?
What have you come up with so far?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement