1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
|
#include <iostream>
using namespace std;
int main()
{
char choice1, choice2, rerun;
do
{
cout << "enter first choice ";
cin >> choice1;
switch (choice1)
{
case 'R':
case 'r':
do
{
cout << "Enter second choice ";
cin >> choice2;
if (choice2 == 'R' || choice2 == 'r')
{
cout << "Tie, nobody wins" << endl;
break;
}
else if (choice2 == 'P' || choice2 == 'p')
{
cout << "Player 2 wins. Paper covers rock" << endl;
break;
}
else if (choice2 == 'S' || choice2 == 's')
{
cout << "Player 1 wins. Rock breaks scissors." << endl;
break;
}
else
{
cout << "Please enter \'R\', \'r\', \'P\', \'p\', \'S\' or \'s\'." << endl;
}
} while ((choice2 != 'R' || choice2 != 'r') && (choice2 != 'P' || choice2 != 'p') && (choice2 != 'S' || choice2 != 's'));
break;
case 'P':
case 'p':
do
{
cout << "Enter second choice ";
cin >> choice2;
if (choice2 == 'R' || choice2 == 'r')
{
cout << "Player 1 wins. Paper covers rock" << endl;
break;
}
else if (choice2 == 'P' || choice2 == 'p')
{
cout << "Tie, nobody wins" << endl;
break;
}
else if (choice2 == 'S' || choice2 == 's')
{
cout << "Player 2 wins. Scissors cuts paper" << endl;
break;
}
else
{
cout << "Please enter \'R\', \'r\', \'P\', \'p\', \'S\' or \'s\'." << endl;
}
} while ((choice2 != 'R' || choice2 != 'r') && (choice2 != 'P' || choice2 != 'p') && (choice2 != 'S' || choice2 != 's'));
break;
case 'S':
case 's':
do
{
cout << "Enter second choice ";
cin >> choice2;
if (choice2 == 'R' || choice2 == 'r')
{
cout << "Player 2 wins. Rock breaks scissors." << endl;
break;
}
else if (choice2 == 'P' || choice2 == 'p')
{
cout << "Player 1 wins. Scissors cuts paper." << endl;
break;
}
else if (choice2 == 'S' || choice2 == 's')
{
cout << "Tie, nobody wins." << endl;
break;
}
else
{
cout << "Please enter \'R\', \'r\', \'P\', \'p\', \'S\' or \'s\'." << endl;
}
} while ((choice2 != 'R' || choice2 != 'r') && (choice2 != 'P' || choice2 != 'p') && (choice2 != 'S' || choice2 != 's'));
break;
default:
cout << "Please enter \'R\', \'r\', \'P\', \'p\', \'S\' or \'s\'" << endl;
break;
}
cout << "run again? Y\\N ";
cin >> rerun;
} while (rerun == 'Y' || rerun == 'y');
system("pause");
return(0);
}
|