I wanted to create a do while loop, that if the user wants to repeat the action, the program starts again, however after the program is supposed to repeat, the 1. getlin(cin, string) gets irgnored. The 2. getline(cin, string) works fine. It's a calculator that solves terms being put in by the User via getline(cin,string).
do
{
cout << "Please enter a term: ";
getline(cin, s); //This gets ignored once repeated
while( correctTerm(s) == 0)
{
cout << "Please only use allowed characters: " ;
getline(cin,s); //This works fine
}
term = split(s, ' '); //splits string into a vector
cout << calculate(term) << endl; //prints the answer to the term
cout << "Do you want to enter a new term?(Y/N)";
cin >> answer; //This works too
}
while(answer == 'Y');
Aucun commentaire:
Enregistrer un commentaire