I'm wanting to take some programming classes at my college next semester, so I figured I would practice a bit before hand. I've never done any kind of programming before, so I thought it would be fun.
I've been trying to make this little text-rpg-like program just for fun and to practice various concepts, but these if then statements are giving me trouble.
I'm basically asking the user if the information is correct. If it is, the game will move on, if not, then it will return to the previous question so they may put in the correct answer... and then it will move on after that.
Right now, the code inside the if then statements are very bare, and I only put those there so I can test answering yes or no.
I really want to continue asking some more questions when it moves on eventually.
My problem, is that when putting either yes or no in as an answer... my program just closes down upon hitting enter. =/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
#include <iostream>
using namespace std;
int main()
{
char play[30];
char name[40];
int age;
char city[30];
char answer;
cout << "Welcome to Bobby's stupid RPG game\n\nType 'play' to begin. ";
cin >> play;
cout << "\n";
cout << "Before you begin your quest, we must\nfirst know a few things about you...\n\nWhat is your name? ";
cin >> name;
cout << "\n";
cout << "Your name will be " << name << ".\nIs this correct? (yes or no) ";
cin >> answer;
if ( answer == 'no' )
cout << "Sorry." << endl;
else if ( answer == 'yes' )
cout << "Ok great.";
return 0;
}
|