Can anyone see why the while loop isnt going back to the start of my program? When I click 'Y' it continue my program where else it should loop back to the start.
Remove the semicolon that's on the same line as the if statements - that's ending the if right there. Also - the ! means that you're checking if the opposite of that statement is true. So if again is not 'Y', you're asking them to add on to their order. And if again is not 'N', you're giving the goodbye message.
1 2 3 4 5
if (!(again == 'Y'));
{
cout << "Please add S, M or L onto your Order!" << endl;
cin >> size;
}
1 2 3 4
if (!(again == 'N'));
{
cout << "Thanks! Goodbye!\n";
}
If you are using the stream extraction operators (i.e. '>>'), you don't need to ignore beforehand. What is probably happening is that you last used getline, so there is nothing to ignore, and instead is ignoring your input. Either remove the cin.ignore() line or replace it with cin.sync() (which doesn't have that problem).
@ NT3, ive found the same problem again but at a different spot and ive tired your idea but I cant get it to work, requires me to type twice for an input.
this part, full code below this code - starting at line 106 to 119
1 2 3 4 5 6 7 8 9 10 11 12 13
cout << "Would you like to add onto your order (Y/N)?\n";
cin >> again;
if (again != 'Y' || again != 'N') {
}
elseif (again == 'Y')
{
cout << "Please Enter the following information \n";
cout << "Please add S, M or L onto your Order! \n";
//cin.clear();
//cin.ignore();
cin.sync();
cin >> size;
Problem with the or operator is you are Checking if it is Not Y or Not Y, it is always going to be either Not Y or Not Y so that condition will always return true. If you put the && it makes sure it's not either Y or N.