Jul 24, 2014 at 10:50pm UTC
I was trying to make a program that would let me create and revise a new character's name and class using a while loop, but I think my loop is flawed somehow. Can someone take a look at line 33 (the while declaration)?
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
struct guildmember {
string Name;
string Class;
};
guildmember NewChar;
void printstats (string, string);
int main ()
{
string mystr;
cout << "Enter name: ";
getline (cin,mystr);
stringstream(mystr) >> NewChar.Name;
cout << "Enter class: ";
getline (cin,mystr);
stringstream(mystr) >> NewChar.Class;
cout << "\n";
printstats (NewChar.Name, NewChar.Class);
cout << "Is this correct? (Y/N)";
char n;
cin >> n;
while (n == 'N' == 'n')
{
cout << "Enter name: ";
getline (cin,mystr);
stringstream(mystr) >> NewChar.Name;
cout << "Enter class: ";
getline (cin,mystr);
stringstream(mystr) >> NewChar.Class;
cout << "\n";
printstats (NewChar.Name, NewChar.Class);
cout << "Is this correct? (Y/N)";
cin >> n;
}
return 0;
}
void printstats (string Name, string Class)
{
cout << "Your name is " << NewChar.Name << "\n";
cout << "Your class is " << NewChar.Class << "\n";
}
Jul 24, 2014 at 10:52pm UTC
while (n == 'N' || n == 'n' )
Jul 24, 2014 at 10:57pm UTC
It works. That was a simple fix, but I couldn't find it until you pointed it out. Thank you!