In: Computer Science
Write a C++ program that prompts the user (or “Player 1”) to input an integer value between 1 and 3 (where 1=paper, 2=scissor, and 3=rock). This input should be passed into a string function called player_RPS(), and returns a string value indicating the selection of paper, scissors, or rock (as mentioned above). Next, the returned string value, along with a generated input from the computer, should be passed into a void function called RPS_comparison(), and determines whether the user’s input or the computer’s generated input is the winner or if both inputs result in a tie.
This program should play this game ten consecutive times and call a function named winner_tally_to_file()to append the winner (either PLAYER1-WINS!!!, COMPUTER-WINS!!!, or TIE!!!) of each match to a text file called rps.txt. After the 10thmatch, this program should call a function named official_tally_from_file() to read the stored data from the rps.txt file back into the program, place this data into a 2x5 two-dimensional array, and print this data to screen after the array is traversed. While this data is being stored in the array, the program should tally the number wins for Player 1, Computer, and TIE, respectively, and output the entity with the most wins:
Please Code in C++
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
void winner(int selection, int compSelection)
{
if (selection == 1)
{
if (compSelection == 1)
cout << "It's a tie!\n\n\n\n";
else if (compSelection == 2)
cout << " you loose!\n\n\n\n";
else if (compSelection == 3)
cout << " You win!\n\n\n\n";
}
else if (selection == 2)
{
if (compSelection == 2)
cout << "It's a tie!\n\n\n\n";
else if (compSelection == 1)
cout << " You win!\n\n\n\n";
else if (compSelection == 3)
cout << "you loose!\n\n\n\n";
}
else if (selection == 3)
{
if (compSelection == 3)
cout << "It's a tie!\n\n\n\n";
else if (compSelection == 2)
cout << "You win!\n\n\n\n";
else if (compSelection == 1)
cout << " you lo0se!\n\n\n\n";
}
}
int main()
{
srand((unsigned)time(0));
int comp = (rand()%3)+1;
int user;
int tie=0;
int win=0;
int loose=0;
cin >> user;
cout << "Computer Selects " << comp <<
endl;
winner(user, comp);
for(int i=0,i<10;i++)
{
if(user == comp
)system("pause");
return 0;
}