I cant figure out why this wont work. Everything work until the user enters their reply then it crashes. I am not getting any build errors and I am a little lost here. Please help.
After you cin>>reply there is a '\n' left in the stream.
If reply is 'Y" no problem since the program exits.
But if reply is 'N' you go to getline(cin, str);.
This returns an empty string since getline extracts all characters before a '\n' and then discards the '\n'. Remember there is still a '\n' in the stream.
To fix you must make sure the cin stream is empty.
An easy fix without using numeric limits is to getline into a string after the cin>>reply which will remove the '\n'.
1 2 3 4 5 6 7 8 9 10 11 12
...
cout << "Would you like to quit Y / N" << endl;
cin >> reply;
getline(cin,str); /// now stream is empty, str's value will be changed at top of loop
reply = toupper(reply);
if (reply == 'Y')
{
Quit = true;
}
}
return 0;
}