c++ while loop problem?

I'm extremely new to c++ coding, but I've read a few tutorials and have learned some very basic coding. I'm trying to write a code for a simple multiplayer Rock Paper Scissors game but i cant get it to loop if you type anything besides 1, 2, or 3. it just keeps repeating this part of the code:

default:

system("cls");

cout << "invalid entry\nplease enter either 1, 2, or 3\n";

system("pause");

b = (0);

break;

i probably did a lot of things wrong so any help would be appreciated.

Here's what i have so far:

//rock paper scissors

#include <iostream>

#include <string>

using namespace std;

//p1 input

int a;

//loop variable

int b;

//p2 input

int c;

int main()

{

//p1 txt

while (b == 0)

cout << "player 1,choose one of the following:" << endl;

cout << "1) rock\n";

cout << "2) paper\n";

cout << "3) scissors\n";

cin >> a;

b = (1);

//p1 input check

while (b == 1)

{

switch (a){

case 1:

cout << "rock\n";

system("pause");

b = (-1);

break;

case 2:

cout << "paper\n";

system("pause");

b = (-1);

break;

case 3:

cout << "scissors\n";

system("pause");

b = (-1);

break;

default:

system("cls");

cout << "invalid entry\nplease enter either 1, 2, or 3\n";

system("pause");

b = (0);

break;

}

}

//p2 txt

while (b == -1)

{

system("cls");

cout << "player 2,choose one of the following:" << endl;

cout << "1) rock\n";

cout << "2) paper\n";

cout << "3) scissors\n";

cin >> c;

b = (3);

}

//p1 input check

while (b == 3)

{

switch (c){

case 1:

cout << "rock\n";

system("pause");

b = (-3);

break;

case 2:

cout << "paper\n";

system("pause");

b = (-3);

break;

case 3:

cout << "scissors\n";

system("pause");

b = (-3);

break;

default:

system("cls");

cout << "invalid entry\nplease enter either 1, 2, or 3\n";

system("pause");

b = (-1);

break;

}

}

//winning deccision

while (b == -3)

{

}

}

i want it to loop all of this:

while (b == 0)

cout << "player 1,choose one of the following:" << endl;

cout << "1) rock\n";

cout << "2) paper\n";

cout << "3) scissors\n";

cin >> a;

b = (1);

//p1 input check

while (b == 1)

{

switch (a){

case 1:

cout << "rock\n";

system("pause");

b = (-1);

break;

case 2:

cout << "paper\n";

system("pause");

b = (-1);

break;

case 3:

cout << "scissors\n";

system("pause");

b = (-1);

break;

default:

system("cls");

cout << "invalid entry\nplease enter either 1, 2, or 3\n";

system("pause");

b = (0);

break;

}

Please enter comments
Please enter your name.
Please enter the correct email address.
You must agree before submitting.

Answers & Comments


Helpful Social

Copyright © 2024 Q2A.ES - All rights reserved.