So basically what i'm trying to do using C++ is make a program that plays Rock Paper Scissors(or our version Cockroach, Foot, Nuclear Bomb) and i have the entire program working in a for loop to repeat 25 times. However i need to it be so that when the user enters there selection(cockroach,foot, or nuclear bomb) it has to reject the input and re-prompt the user if they don't enter the correct character. I tried setting up a while loop but it infinite loops even when i re-enter a correct character. Any help you guys could offer would be great. I also tried to set up a boolean but i couldn't really figure that out. My program follows...
#include <iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int numWins=0;
int numLosses=0;
int numDraws=0;
char choice;
unsigned seed=time(0);
srand(seed);
bool status;
for(int index=0;index<=24;index++)
{
int answer=(rand()%10);
if(answer>=0&&answer<4)
{
cout<<"I have selected Foot(F)!Please input your selection!"<<endl;
cin>>choice;
/*bool isValid(char choice);
{
if (choice=='n'||choice=='N'||choice=='c'||choice=='C'||choice=='f'||choice=='F')
status = true;
else
status = false;
return status;
}*/
while (choice!='n'&&choice!='N'&&choice!='c'&&choice!='C'&&choice!='f'&&choice!='F')
{
cout<<"It seems you entered an incorrect answer! Try again and make sure it is a lower/capital N,F,or C"<<endl;
cin>>choice;
}
if(choice=='N'||choice=='n')
{
cout<<"Gah! You beat me!"<<endl;
numLosses++;
}
if(choice=='F'||choice=='f')
{
cout<<"Well it looks like we tied this time!"<<endl;
numDraws++;
}
if(choice=='C'||choice=='c')
{
cout<<"Yay! I win this round!"<<endl;
numWins++;
}
}
else if(answer>=4&&answer<7)
{
cout<<"I have selected Nuclear Bomb(N)!!! Input your selection!"<<endl;
cin>>choice;
while (choice!=('N'||'n'||'c'||'C'||'F'||'f'))
{
cout<<"It seems you entered an incorrect answer! Try again and make sure it is a lower/capital N,F,or C"<<endl;
cin>>choice;
}
if(choice=='N'||choice=='n')
{
cout<<"Well it looks like we tied this time!"<<endl;
numDraws++;
}
if(choice=='F'||choice=='f')
{
cout<<"Yay! I win this round!"<<endl;
numWins++;
}
if(choice=='C'||choice=='c')
{
cout<<"Gah! You beat me!"<<endl;
numLosses++;
}
}
else if(answer>=7||answer<=9)
{
cout<<"I have selected Cockroach(C)! Please input your selection!"<<endl;
cin>>choice;
while (choice!=("N"||"n"||"c"||"C"||"F"||"f"))
{
cout<<"It seems you entered an incorrect answer! Try again and make sure it is a lower/capital N,F,or C"<<endl;
cin>>choice;
}
if(choice=='N'||choice=='n')
{
cout<<"Yay! I win this round!"<<endl;
numWins++;
}
if(choice=='F'||choice=='f')
{
cout<<"Gah! You beat me!"<<endl;
numLosses++;
}
if(choice=='C'||choice=='c')
{
cout<<"Well it looks like we tied this time!"<<endl;
numDraws++;
}
}
}
cout<<"Great game! I loved playing with you! Maybe we can play again sometime?"<<endl;
cout<<"We tied: "<<numDraws<<" times"<<endl;
cout<<"You won: "<<numLosses<<" times"<<endl;
cout<<"I won: "<<numWins<<" times"<<endl;
if(numWins>numLosses)
{
cout<<"Overall i won! You played great though!"<<endl;
}
else if(numLosses>numWins)
{
cout<<"Overall you won! Great job! I'll do better next time!"<<endl;
}
else if(numLosses==numWins)
{
cout<<"It seems that we tied this time!! Wow!"<<endl;
}
return 0;
}
Also, the boolean has been commented out. Thanks in advance for your time and your help.