0

I have been trying to get my program to ask the user if the want to run the program again before exiting. I have been using he following while loop. It isn't working, any suggestions.

char again;
again = 'Y';
while (again == 'Y','y')
{

//
// program
//

cout << "Enter the number 1 if you wish to run the program again!!!";
cin >> again;
}

3
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by dr.eu
0

You can't use commas that way. You want to write again == 'Y' || again == 'y' .

The comma operator behaves in the following way. The left side of the comma operator is evaluated first, and then the right side is evaluated, and the expression's return value will be the right side. For example, the expression 2, 3 will evaluate to 3 .

You should basically never use the comma operator for this purpose, but there are some interesting idioms found in some libraries where the operator is overloaded to have a different meaning.

0

You have a mistake by asking user:

cout << "Enter the number 1 if you wish to run the program again!!!";

Better way is to write:

cout << "Enter the Y or y if you wish to run the program again!!!";
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.