Hey folks. I'm hoping I can get some help here. I have to make this program to play the game paper, rock scissors. I am having a few issues with the program.
1.) I dont think i am using the rand() correctly
2.) After entering your choice for Paper Rock or Scissors it just ends the program.
3.) I cant figure out the correct way to display the win/loss/tie/percentage stats/and number of games played
4.) and lastly I am having a problem figuring out how to loop the program back to asking if you want to play the game.
Any help is appricated. Heres the code. Thanks in advance!
//This program is a Rock, Paper, Scissor game. It will ask you if you want to
//play the game, and if yes, will have you make a choice and determine the
//winner and keep score until the uder quits.
#include <iostream>
#include <cstdlib>
#include <ctype.h>
using namespace std;
//*******************************************************
//Definition of function displayMenu *
//This function displays the menu choices. *
//*******************************************************
void displayMenu ()
{
int userChoice;
userChoice = 1 or 2 or 3;
cout << "1) Paper\n";
cout << "2) Rock\n";
cout << "3) Scissors\n";
cout << "Please make your choice(1-3):\n";
do
cin >> userChoice;
while (!userChoice);
}
//*******************************************************
//Definition of function displayEnd *
//This fuction is used to store stats *
//*******************************************************
void displayEnd ()
{
int win, lose, tie, numGames, percent;
win = 0;
lose = 0;
tie = 0;
percent = win / numGames;
cout << "So far your have played " << numGames << " sessions and have won " << win << ", tied " << tie << ", and lost " << lose << " for a winning percent of " << percent << "%.\n";
}
//*******************************************************
//Definition of function displayWinner *
//This function is used to determine the winner. *
//*******************************************************
void displayWinner ()
{
int compChoice, win, lose, tie, userChoice;
compChoice = 1 + rand() % 3;
if (userChoice == 1 && compChoice == 2)
cout << "You have chosen paper and the computer has chosen rock. You win!\n";
win++;
if (userChoice == 2 && compChoice == 3)
cout << "You have chosen rock and the computer has chosen scissors. You win!\n";
win++;
if (userChoice == 3 && compChoice == 1)
cout << "You have chosen scissors and the computer has chosen paper. You win!\n";
win++;
if (userChoice == 1 && compChoice == 3)
cout << "You have chosen paper and the computer has chosen scissors. You lose!\n";
lose++;
if (userChoice == 2 && compChoice == 1)
cout << "You have chosen rock and the computer has chosen paper. You lose!\n";
lose++;
if (userChoice == 3 && compChoice == 2)
cout << "You have chosen scissors and the computer has chosen rock. You lose!\n";
lose++;
if (userChoice == 1 && compChoice == 1)
cout << "You have chosen paper and the computer has chosen paper. You tied!\n";
tie++;
if (userChoice == 2 && compChoice == 2)
cout << "You have chosen rock and the computer has chosen rock. You tied!\n";
tie++;
if (userChoice == 3 && compChoice == 3)
cout << "You have chosen scissors and the computer has chosen scissors. You tied!\n";
tie++;
}
int main ()
{
int win, lose, tie, numGames, percent, choice, userChoice;
win = 0;
lose = 0;
tie = 0;
percent = win / numGames;
{
cout << "Welcome! Want to play a game of Paper Rock Scissors?\n";
{
do
{
cout << "Press 1 to Play and 2 to Quit.\n";
cin >> choice;
}
while (choice >> 2);
if (choice == 1)
{
displayMenu();
numGames++;
displayWinner();
}
if (choice == 2)
{
displayEnd();
}
}
}
return 0;
}