0

Hi! I am trying to modify the game rock, paper scissors but I'm having a hard time to loop a certain case in a switch statement

Here is the code. I wanted to make a loop of the cases (if possible) whenever the user wanted to continue the game. I'd appreciate it if you could give me some advice. Thank you in advance! #include<iostream> #include <cstdlib> #include <ctime> using namespace std; int main() { int m, number,usernumber; char repeat,userpick; int userscore,compscore,value; value=0; userscore=0; compscore=0; cout<< "Choose a mode\n" "(1) Normal\n" "(2) Fun\n" "Enter the number of the mode you want: "; cin>>m; system("cls"); repeat: while(true) { switch (m) { case 1: srand(time(0)); number = 1 + (rand() % 3) ; userscore=userscore+value; compscore=compscore+value; cout<<"\nYour Score: "<<userscore<<endl; cout<<"Computers Score: "<<compscore<<endl; cout<<"Pick either (R)ock, P(A)per, or (S)cissors. \n"; cin>>userpick; if(userpick=='r'|| userpick=='R'){ usernumber=1; cout<<"\nso you picked rock";} else if(userpick=='a'|| userpick=='A'){ usernumber=2; cout<<"\nso you picked paper";} else if(userpick=='s'|| userpick=='S'){ usernumber=3; cout<<"\nso you picked scissors";} else{ cout<<"INVALID INPUT,TRY AGAIN!"<<endl; system("pause"); system("cls"); goto repeat; } if(usernumber==number){ cout<<"\nuser picked "<<userpick<<" and the computer picked the same thing, so it is a draw\n"; userscore++; compscore++;} else if(usernumber==1 && number==2){ cout<<"\npaper covers rock, you lose\n"; compscore++;} else if(usernumber==1 && number==3){ cout<<"\nrock beats scissors, you win\n"; userscore++;} else if(usernumber==2 && number==1){ cout<<"\npaper covers rock, you win\n"; userscore++;} else if(usernumber==2

29th May 2021, 3:30 PM
emsii groove
emsii groove - avatar
1 Answer
+ 1
Where you want to make loop?
29th May 2021, 4:31 PM
‎ àșž