Code
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <string>
using namespace std;
int main()
{
string playerName;
char replay;
int cpuPick, playerPick, gamesPlayed, win, loss;
gamesPlayed = 0;
win = 0;
loss = 0;
cout << "Hello player, please enter your name" << endl;
cin >> playerName;
cout << endl << "Welcome " << playerName << ", are you feeling lucky?" << endl;
cout << "So we are going to play a game of Rock, Paper, Scissors." << endl;
cout << "Are you ready to test your luck?" << endl << endl;
restart:
srand( time(0) );
cpuPick = rand() % 3 + 1;
cout << "Please select from the following:" << endl;
cout << "1 - Rock" << endl;
cout << "2 - Paper" << endl;
cout << "3 - Scissors" << endl << endl;
cout << "Please make your selection." << endl;
cin >> playerPick;
cout << endl <<"Lets see how you do." << endl;
switch (cpuPick)
{
case 1:
if ( playerPick == 1 )
cout << "Rock and rock, nobody wins." << endl;
cout << "Try again:" << endl;
gamesPlayed++;
cout << "Want to play again? Press 'Y' or 'y' if you do." << endl << endl;
cin >> replay;
if (replay == 'Y' || replay == 'y')
{
system("CLS");
goto restart;
}
else
{
system("CLS");
cout << "You won " << win << " out of " << gamesPlayed << ". Thats great." << endl;
cout << "And you only lost " << loss << " times." << endl;
return(0);
}
break;
if ( playerPick == 2 )
cout << "Paper covers rock." << endl;
cout << "Great job." << endl;
win++;
gamesPlayed++;
cout << "Want to play again? Press 'Y' or 'y' if you do." << endl << endl;
cin >> replay;
if (replay == 'Y' || replay == 'y')
{
system("CLS");
goto restart;
}
else
{
system("CLS");
cout << "You won " << win << " out of " << gamesPlayed << ". Thats great." << endl;
cout << "And you only lost " << loss << " times." << endl;
return(0);
}
break;
if ( playerPick == 3 )
cout << "Scissors are crushed by rock." << endl;
cout << "Maybe next time." << endl;
loss++;
gamesPlayed++;
cout << "Want to play again? Press 'Y' or 'y' if you do." << endl << endl;
cin >> replay;
if (replay == 'Y' || replay == 'y')
{
system("CLS");
goto restart;
}
else
{
system("CLS");
cout << "You won " << win << " out of " << gamesPlayed << ". Thats great." << endl;
cout << "And you only lost " << loss << " times." << endl;
return(0);
}
break;
case 2:
if ( playerPick == 1 )
cout << "Paper covers rock." << endl;
cout << "Maybe next time." << endl;
loss++;
gamesPlayed++;
cout << "Want to play again? Press 'Y' or 'y' if you do." << endl << endl;
cin >> replay;
if (replay == 'Y' || replay == 'y')
{
system("CLS");
goto restart;
}
else
{
system("CLS");
cout << "You won " << win << " out of " << gamesPlayed << ". Thats great." << endl;
cout << "And you only lost " << loss << " times." << endl;
return(0);
}
break;
if ( playerPick == 2 )
cout << "Paper and paper do nothing." << endl;
cout << "Try again." << endl;
gamesPlayed++;
cout << "Want to play again? Press 'Y' or 'y' if you do." << endl << endl;
cin >> replay;
if (replay == 'Y' || replay == 'y')
{
system("CLS");
goto restart;
}
else
{
system("CLS");
cout << "You won " << win << " out of " << gamesPlayed << ". Thats great." << endl;
cout << "And you only lost " << loss << " times." << endl;
return(0);
}
break;
if ( playerPick == 3 )
cout << "Scissors cut paper." << endl;
cout << "Great job." << endl;
win++;
gamesPlayed++;
cout << "Want to play again? Press 'Y' or 'y' if you do." << endl << endl;
cin >> replay;
if (replay == 'Y' || replay == 'y')
{
system("CLS");
goto restart;
}
else
{
system("CLS");
cout << "You won " << win << " out of " << gamesPlayed << ". Thats great." << endl;
cout << "And you only lost " << loss << " times." << endl;
return(0);
}
break;
case 3:
if ( playerPick == 1 )
cout << "Rock breaks scissors." << endl;
cout << "Great job." << endl;
win++;
gamesPlayed++;
cout << "Want to play again? Press 'Y' or 'y' if you do." << endl << endl;
cin >> replay;
if (replay == 'Y' || replay == 'y')
{
system("CLS");
goto restart;
}
else
{
system("CLS");
cout << "You won " << win << " out of " << gamesPlayed << ". Thats great." << endl;
cout << "And you only lost " << loss << " times." << endl;
return(0);
}
break;
if ( playerPick == 2 )
cout << "Scissors cut paper." << endl;
cout << "Maybe next time." << endl;
loss++;
gamesPlayed++;
cout << "Want to play again? Press 'Y' or 'y' if you do." << endl << endl;
cin >> replay;
if (replay == 'Y' || replay == 'y')
{
system("CLS");
goto restart;
}
else
{
system("CLS");
cout << "You won " << win << " out of " << gamesPlayed << ". Thats great." << endl;
cout << "And you only lost " << loss << " times." << endl;
return(0);
}
break;
if ( playerPick == 3 )
cout << "Scissors and scissors do nothing." << endl;
cout << "Try again." << endl;
gamesPlayed++;
cout << "Want to play again? Press 'Y' or 'y' if you do." << endl << endl;
cin >> replay;
if (replay == 'Y' || replay == 'y')
{
system("CLS");
goto restart;
}
else
{
system("CLS");
cout << "You won " << win << " out of " << gamesPlayed << ". Thats great." << endl;
cout << "And you only lost " << loss << " times." << endl;
return(0);
}
break;
}
}
vagy átirni ezt magyarra vagy kurvára mind1 csak legyen meg ez a szar es mukodjon :DD