this is a very simple RPS game and i ran into a prob. heres the code
#include <iostream> // for cout/cin
#include <cstdlib> // for rand/srand
#include <ctime> // for time
#include <cctype> // for case conversion
using namespace std;
char rps;
char ai;
char redo = 'Y'; // all the variables
unsigned int num;
int win = 0;
int lose = 0;
void Convert(){ // func to check if input is lower and to conv to upper
cin>>rps;
if(islower(rps)) rps=toupper(rps);
}
void Random(){ // for random ai num
srand(time(0));
num = rand()%2;
}
void AiConvert(){ // conv random ai num to letter
switch(num){
case 0:
ai = 'R';
break;
case 1:
ai = 'P';
break;
case 2:
ai = 'S';
break;
default: ai = 'P';
}
}
void Compare(); // compare func
void Display(){ // func to display winnings and losses
cout<<"Total winnings: "<<win<<endl;
cout<<"Total loses: "<<lose<<endl;
}
int main(){ // main func
cout<<"Welcome to my RPS!\nCall which option you want by initial!\n";
do{ // main loop
Convert();
Random();
AiConvert();
cout<<"AI picked: "<<ai<<endl;
Compare();
Display();
cout<<"Wanna try again? (Y/N)"<<endl;
cin>>redo; // see if still wanna play
if(islower(redo)) redo=toupper(redo);
}while(redo!='N');
}
void Compare(){ // compare func coding
if(rps=='R'||ai=='P'){
cout<<"You lose!"<<endl;
lose++;
}
if(rps=='R'||ai=='S'){
cout<<"You win!"<<endl;
win++;
}
if(rps=='P'||ai=='S'){
cout<<"You lose!"<<endl;
lose++;
}
if(rps=='P'||ai=='R'){
cout<<"You win!"<<endl;
win++;
}
if(rps=='S'||ai=='R'){
cout<<"You lose!"<<endl;
lose++;
}
if(rps=='S'||ai=='P'){
cout<<"You lose!"<<endl;
win++;
}
if (rps==ai){
cout<<"Tieee!"<<endl;
}
}
when i run it the ai runs like 3 time but only asks for my input once.
and im just lost. all help appreciated