I'm trying to preform a loop, using a combination of a if/else and while loops. I set a boolean "repeat1" to true, to enter the while loop. Then when I went the user to pick to repeat or move on, they enter a Y or N, if Y, keep repeat1=true, if n set repeat1=false

for some reason, repeat1 is always returning a value of false, can't figure out why.

while(repeat1== true)
{ ...
cout << "Would you like to add another item? (Y/N): ";
			cin >> addAnother;
			if(addAnother == 'y' && addAnother == 'Y')
				repeat1= true;
				repeat1= false;

Edited by Gonzo14: add details of problem

5 Years
Discussion Span
Last Post by Gonzo14

Maybe you should try:

repeat1 = true;//assignment

while ( repeat1 == true )//equals

Edited by gerard4143: n/a


Or the less redundant:

repeat1 = true;

while (repeat1)
    cout << "Would you like to add another item? (Y/N): ";
    cin >> addAnother;
    repeat1 = (addAnother == 'y' || addAnother == 'Y');

Note that I fixed the condition for checking against 'y' or 'Y'. Before it used && instead of ||, and there's no way addAnother could be both 'y' and 'Y'. That was why it was always false. :) This would be a good place for toupper() or tolower():

repeat1 = (toupper(addAnother) == 'Y');

Edited by deceptikon: n/a


thank you very much for the help!

Edited by Gonzo14: n/a

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.