Question

In: Computer Science

Write a C++ program that prompts the user (or “Player 1”) to input an integer value...

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++

Solutions

Expert Solution

  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <ctime>
  4. using namespace std;
  5. /*function to compare selection of user and computer ,
  6. and return that your is winner ,loser or its a tie.*/
  7. void winner(int selection, int compSelection)
  8. {
  9. /*
  10. 1=paper;
  11. 2=scissor;
  12. 3=rock;
  13. */
  14. if (selection == 1)
  15. {
  16. if (compSelection == 1)
  17. cout << "It's a tie!\n\n\n\n";
  18. else if (compSelection == 2)
  19. cout << " you loose!\n\n\n\n";
  20. else if (compSelection == 3)
  21. cout << " You win!\n\n\n\n";
  22. }
  23. else if (selection == 2)
  24. {
  25. if (compSelection == 2)
  26. cout << "It's a tie!\n\n\n\n";
  27. else if (compSelection == 1)
  28. cout << " You win!\n\n\n\n";
  29. else if (compSelection == 3)
  30. cout << "you loose!\n\n\n\n";
  31. }
  32. else if (selection == 3)
  33. {
  34. if (compSelection == 3)
  35. cout << "It's a tie!\n\n\n\n";
  36. else if (compSelection == 2)
  37. cout << "You win!\n\n\n\n";
  38. else if (compSelection == 1)
  39. cout << " you lo0se!\n\n\n\n";
  40. }
  41. }
  42. int main()
  43. {
  44. srand((unsigned)time(0));
  45. int comp = (rand()%3)+1;
  46. int user;
  47. int tie=0;
  48. int win=0;
  49. int loose=0;
  50. cin >> user;
  51. cout << "Computer Selects " << comp << endl;
  52. /*function calling*/
  53. winner(user, comp);
  54. for(int i=0,i<10;i++)
  55. {
  56. if(user == comp)
  57. {
  58. cout<<"its a tie"<<endl;
  59. tie++;
  60. }
  61. else if(user =1 && comp=3 !! user =2 && comp=1 !! user=3 && comp=2)
  62. {
  63. cout<<"you win"<<endl;
  64. win++;
  65. }
  66. else
  67. {
  68. cout<<"you loose"<<endl;
  69. lose++;
  70. }
  71. }
  72. system("pause");
  73. return 0;
  74. }

Related Solutions

Include<stdio.h> In C program Write a program that prompts the user to enter an integer value....
Include<stdio.h> In C program Write a program that prompts the user to enter an integer value. The program should then output a message saying whether the number is positive, negative, or zero.
Write a C++ program which prompts the user to enter an integer value, stores it into...
Write a C++ program which prompts the user to enter an integer value, stores it into a variable called ‘num’, evaluates the following expressions and displays results on screen. num+5, num-3, (num+3) – 2, ((num+5)*2 / (num+3)) For performing addition and subtraction, you are allowed to use ONLY the increment and decrement operators (both prefixing and postfixing are allowed). You must remember that using increment/decrement operators changes the original value of a number. Indent your code and include comments for...
in C++ programing language Write a program that prompts the user for an integer, then prints...
in C++ programing language Write a program that prompts the user for an integer, then prints all of the numbers from one to that integer, separated by spaces. Use a loop to print the numbers. But for multiples of three, print "Fizz" instead of the number, and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz". Drop to a new line after printing each 20 numbers. If the user typed...
Write a program in c++ that prompts the user to input a coin collection of number...
Write a program in c++ that prompts the user to input a coin collection of number of quarters, dimes, nickels and pennies. The program should then convert the coin collection into currency value as dollars. The coin values should all be whole numbers and the resulting currency value should be displayed with two decimals. An example of user interaction is as follows: Coin Convertor Enter number of quarters: 3 Enter number of dimes: 1 Enter number of nickels: 4 Enter...
Write a program that prompts a user for an integer from 1 to 99 and prints...
Write a program that prompts a user for an integer from 1 to 99 and prints it as an amount in words. The program will loop in case the user wants to input an additional number. If the user enters -99, the program will exit. Example: Input: 89 Output: Eighty nine Input: 45 Output: Fourty five Input: -99 Output: Have a nice day. <program exits> For this project, you are to: 1) You should validate any data coming from the...
Problem 1 Write a program that prompts the user to enter an integer It then tells...
Problem 1 Write a program that prompts the user to enter an integer It then tells the user if the integers is a multiple of 2, 3, 5, 7 or none of the above. Program language is C Ex. Enter an integer 12 You entered 12 The number you entered is a multiple of 2 ----------------------------------------------- Enter an integer 11 You entered 11 The number you entered is not a multiple of 2, 3, 5, or 7
Write a program that prompts a user for an integer from 1 to 99 and prints...
Write a program that prompts a user for an integer from 1 to 99 and prints it as an amount in words. The program will loop in case the user wants to input an additional number. If the user enters -99, the program will exit. Example: Input: 89 Output: Eighty nine Input: 45 Output: Fourty five Input: -99 Output: Have a nice day. <program exits> c++ project. need help.
Write a program that prompts the user to enter an integer from 1 to 15 and...
Write a program that prompts the user to enter an integer from 1 to 15 and displays a pyramid, as shown in the following sample run: here............THE PYRAMID HAS TO BE THIS SHAPE AND IT IS DONE IN JAVA PLEASE 7 6 5 4 3 2 1 2 3 4 5 6 7 6 5 4 3 2 1 2 3 4 5 6 5 4 3 2 1 2 3 4 5 4 3 2 1 2 3 4...
Write a complete C++ program that prompts the user for and takes as input, numbers until...
Write a complete C++ program that prompts the user for and takes as input, numbers until the user types in a negative number. the program should add all of the numbers together. Then if the result is less than 20 the program should multiply the result by 3, otherwise subtract 2 from the result. Finally, the program should printout the result.
Write a program that prompts the user to enter a positive integer and then computes the...
Write a program that prompts the user to enter a positive integer and then computes the equivalent binary number and outputs it. The program should consist of 3 files. dec2bin.c that has function dec2bin() implementation to return char array corresponding to binary number. dec2bin.h header file that has function prototype for dec2bin() function dec2binconv.c file with main function that calls dec2bin and print results. This is what i have so far. Im doing this in unix. All the files compiled...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT