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;

Recommended Answers

All 3 Replies

Maybe you should try:

repeat1 = true;//assignment

while ( repeat1 == true )//equals

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');

thank you very much for the help!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.