In: Computer Science
#include <stdio.h>
#include <stdlib.h>
int play_game(int *); // Returns 0 if player won, 1 if the computer won, 2 if there is a tie, and -1 if the player decides to quit
int menu(int *); // Displays choices to user // Receives score array
int main() { srand(42); // Seeding Random with 42
int score[3]; // Array keeping Player, Computer, and Tie Scores
score [0] = 0; // Player - initialized to Zero
score [1] = 0; // Computer - initialized to Zero
score [2] = 0; // Tie - initialized to Zero
int winner=0; // Winner index of
printf("ROCK PAPER SCISSORS!\n\n");
while(winner >=0) // If Winner == -1 -> the game stops {
winner = play_game(score); // Plays the game
. if(winner >=0) // If a value to not stop the game comes in.
score[winner]++; // Increment score counter }
printf("GOOD BYE!\n");
return 0; }
please help with the two functions listed on top.
need to know
int menu(int *): Receives: integer array score Returns: Menu number for Rock, Paper, Scissors, or Exit. Returns -1 for any other number than applicable menu choice Grading: 1) Displays “ROCK PAPER SCISSORS!” at the top of the menu 2) Displays the current score between the player and the computer (including ties) 3) Displays choice numbers for Rock, Paper, Scissors, and Exit. 4) Asks for a choice – If improper choice is given (alpha-numeric and wrong number), asks for another choice 5) Console Display is organized and easily read 6) Code is organized and easily read (Comments where needed) HINT: Use of a switch statement makes the code a little easier to read.
int play_game(int *): Receives: integer array score Returns: an index of score to be incremented. If the player wins, returns 0. If the computer wins, returns 1. If there is a tie, returns 2. Grading: 1) The computer choice is randomly generated between 3 numbers using rand(). 2) Displays BOTH the User choice and the Computer Choice 3) Displays whether the result is a win, loss, or tie for the User. 4) Displays the following statements depending on what was played by the User and Computer “ROCK CRUSHES SCISSORS!” “SCISSORS CUT PAPER!” “PAPER COVERS ROCK!” “TIE – BAZINGA!” 5) Returns 0 if the User won, 1 if the Computer won, and 2 if the User and Computer Tied.
#include <iostream>
#include <cmath>
#include <time.h>
#include <cstdlib>
using namespace std;
int main(){
char ch;
int win = 0;
int tie = 0;
int lose = 0;
do{
int choice;
cout << "--------------------------------------" << endl;
cout << "-- Lets play Rock, Paper, Scissors! --" << endl;
cout << "--------------------------------------" << endl;
cout << "Press 1 for Rock, 2 for Paper, 3 for Scissors:" << endl;
cin >> choice;
int ai = rand() % 3 + 1;
cout << "The computer chose: " << ai << endl;
if(choice == 1 && ai == 1){
cout << "Rock meets Rock its a tie!" << endl;
tie++;
}
else if(choice ==1 && ai== 2){
cout << "Rock is covered by Paper the computer wins!." << endl;
lose++;
}
else if(choice == 1 && ai == 3){
cout << "Rock crushes Scissors you win!" << endl;
win++;
}
else if(choice == 2 && ai == 1){
cout << "Paper covers Rock you win!" << endl;
win++;
}
else if(choice == 2 && ai == 2){
cout << "Paper meets Paper its a tie!" << endl;
tie++;
}
else if(choice == 2 && ai == 3){
cout << "Paper is cut by Scissors the computer wins!" << endl;
lose++;
}
else if( choice == 3 && ai == 1){
cout << "Scissors are crushed by Rock computer wins!" << endl;
lose++;
}
else if( choice == 3 && ai == 2){
cout << "Scissors cuts Paper you win!" << endl;
win++;
}
else if(choice == 3 && ai == 3){
cout << "Scissors meet Scissors its a tie!" << endl;
tie++;
}
else{
cout << "You didn't select 1, 2, or 3" << endl;
}
cout << "Wins: " << win << endl;
cout << "Ties:" << tie << endl;
cout << "Losses:" << lose << endl;
cout << "Would you like to play again? Y/N" << endl;
cin >> ch;
system("CLS");
}while(ch == 'Y' || ch == 'y');
return 0;
}