I've started learning C++ about one week ago and have now "finally" run into a problem I can't figure out on my own.
The code bellow is supposed to let you enter data for one character (D&D/NWN-style), print it to a file and then allow the user to add another character without having to restart the console.
It runs pretty much fine the first time through, but the second time it prints the character name and gender lines to the screen without pausing, thereby only letting you enter gender.
Same for class and level.
I tried adding cout << endl; which didn't do anything at all and cin.get() in several places.
The letter works for int variables but sends strings (which Name and Class are) into an infinite loop of some sort.
I've used the exact same loop in another program where it did, and still does, work fine.
I spent the last couple of hours trying to fix this, looked at similar code from other people, even rewrote the things several tims just in case.
Now I'm hoping that maybe someone here can open my eyes.
In case it matters: I'm using Win XP Pro SP2, Dev C++ 4.9.9.2 and it's a simple console application.
Well, here's the code:
(Ignore the comments, I suck at commenting)
Code:
while ( answer == 'y')
{
// Starting user Input
cout << "What is your character's name?\n)";
getline (cin, Name);
cout << "Which gender is " <<Name << " (m/f)?\n";
cin >> Gender;
cout << "How many classes does " << Name << " have?\n";
cin >> classes;
//Counting and saving classes and levels
for (i=0; i<classes; i++)
{
cout << "Enter class number " << i+1 << ": ";
cin >> Class [i];
cout << "Enter number of levels in this class: " ;
cin >> Level [i];
}
CharOrg << "Name: " << Name << "\nGender: " << Gender << "\nClass: \n";
for (i=0; i<classes; i++)
{
Class [i];
CharOrg << Class [i] << " (" << Level [i] << "), " ;
}
cout << endl;
cout << " Do you wish to enter another character (y/n)? ";
cin >> answer;
} // End while