its not supposed to be rock paper scissors yet, were just making something similar. But im having a problem with an infinite loop and i was wondering if someone could make heads or tails of this
#include <iostream>
#include <string>
usingnamespace std;
int main()
{
int Guess;
char Cont;
bool loop=true;
cout<<"Let's play Rock, Paper, Scissors"<<endl;
cout<<"Enter 1 for Rock, 2 for Paper, 3 for Scissors"<<endl;
while (loop==true)
{
cout<<"Please Guess"<<endl;
cin>>Guess;
switch(Guess)
{
case 1:
cout<<"You chose rock"<<endl;
break;
case 2:
cout<<"You chose paper"<<endl;
break;
case 3:
cout<<"You chose scissors"<<endl;
break;
default:
cout<<Guess<<" is not a valid choice"<<endl;
}
cout<<"Would you like to play again (Y for yes, N for no)?"<<endl;
cin>>Cont;
if (Cont=='y')
loop=true;
}
return(0);
}
You never set loop to false anywhere in your program. It is not possible for the loop to end. Maybe on lines 33 and 34 you meant == 'n' and loop = false;, but even then why not just use the break; statement?
You never set loop to false anywhere in your program. It is not possible for the loop to end. Maybe on lines 33 and 34 you meant == 'n' and loop = false;, but even then why not just use the break; statement?[quote]
@David Look at lines 31 and down, If i type N, will it actually get out of the loop? No it wont. I will go back to the top as if I had typed a y and == is case sensitive so y is not Y.
You could have an else statement after the if with a break statement and that should fix it.