Bored and just wrote this. Anything I did wrong? Anything that can be improved? Relatively new to C++ but I have the basic basics down(I like to think so anyway).
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
void programIntroduction();
void gameLoop();
int playerChoice, cpuChoice, wins=0, losses=0, ties=0;
int main(){
//Displays program name, version, and instructions
programIntroduction();
//This function gets userInput, cpuInput and then checks all the possible outcomes of game.
gameLoop();
return 0;
}
void programIntroduction(){
cout << "ROCK PAPER SCISSORS version 0.2 \n" << endl
<< "Welcome to an exciting game of Rock, Paper, Scissors." << endl
<< "You will face off against the computer. Good luck! \n";
}
void gameLoop(){
//Program returns here if the player choooses to play again
restart:
//Menu selection for players
//Initilize random number and get CPUs choice
srand(time(0));
cpuChoice = rand() % 3 + 1;
cout << "\n1: Rock \n2: Paper \n3: Scissor" << endl
<< "Please make your selection: ";
cin >> playerChoice;
//These 3 if statements handle a tie. It displays the choice and adds 1 tie to the scoreboard.
if(playerChoice == cpuChoice && playerChoice == 1){
cout << "\nYou and the computer picked Rock. Its a draw!" << endl;
ties++;
}
if (playerChoice == cpuChoice && playerChoice == 2){
cout << "\nYou and the computer picked Paper. Its a draw!" << endl;
ties++;
}
if (playerChoice == cpuChoice && playerChoice == 3){
cout << "\nYou and the computer picked Scissor. Its a draw!" << endl;
ties++;
}
//This is playerRock and cpuPaper or cpuScissors.
if (playerChoice == 1 && cpuChoice == 2){
cout << "\nYou picked Rock. The computer picked Paper. You lost!" << endl;
losses++;
}
else if(playerChoice == 1 && cpuChoice == 3){
cout << "\nYou picked Rock. The computer picked Scissor. You won!" << endl;
wins++;
}
//This is playerPaper and cpuRock or cpuScissors.
else if(playerChoice == 2 && cpuChoice == 1){
cout << "\nYou picked Paper. The computer picked Rock. You won!" << endl;
wins++;
}
else if(playerChoice == 2 && cpuChoice == 3){
cout << "\nYou picked Paper. The computer picked Scissor. You lost!" << endl;
losses++;
}
//This is playerScissors and cpuRock or cpuPaper
else if(playerChoice == 3 && cpuChoice == 1){
cout << "\nYou picked Scissor. The computer picked Rock. You lost!" << endl;
losses++;
}
else if(playerChoice == 3 && cpuChoice == 2){
cout << "\nYou picked Scissor. The computer picked Paper. You won!" << endl;
wins++;
}
cout << "\nScoreboard: Wins= " << wins << " Losses= " << losses << " Ties= " << ties << endl;
//Replay loop
char playAgain='No';
cout << "\nType 'y' to play again or 'n' to quit: ";
cin >> playAgain;
while(playAgain != 'n')
goto restart;
}