C++ In general, your program should ask the user for five different test scores,
ID: 3764080 • Letter: C
Question
C++
In general, your program should ask the user for five different test scores, determine which one is the lowest, and calculate and display the average of the remaining four highest scores. The test scores are assumed to be ints. Note that although the test scores in this problem are ints, the average should be calculated as a double. Have it printed out to two decimal places. Notice that this problem includes a requirement to create three different functions besides the main() function. Here are some programming notes for those functions: 1) void getScore() The getScore() function should include a prompt to enter another test score, an input statement, and an input validation loop that makes sure the number entered is between 0 and 100 (inclusive). Once the number passes the input validation loop, the function will return the value back through a reference parameter (not the return mechanism of the function). The return data type on the function is therefore void. 2) void calcAverage() This function will have five input parameters that represent the five test scores for which we are calculating the average. The function will determine the lowest of the five scores by calling the function findLowest(). Once that is determined, it will calculate the average of the remaining four scores and display that information to the screen in a nicely formatted report. (Print out an explanatory statement followed by the average value to two decimal places.) Since it doesn’t pass any data back to the calling program, the return data type on this function is void. 3) int findLowest() Like calcAverage(), this function will have five input parameters. It will determine which of those five is the lowest and pass that information back through the return mechanism of the function. The return data type on this function should therefore be int. Note that of the three functions described above, one function (getScore()) will pass data back to the calling function through a reference input parameter, another function (findLowest()) will pass data back to the calling function through the return mechanism of the function, and the third function (calcAverage()) only displays its results and does not pass anything back to the calling function.
Program 2 – Rock Paper Scissors For this problem, please implement Problem #24 on page 373 of Gaddis, 8th Edition. A scan of the problem is included below for those who don’t have a copy of the book. You should define the following constant integer variables: ROCK, PAPER, SCISSORS Notice that this problem includes a requirement to create several functions besides the main() function. Below are notes for the functions you will create in your program. Your program should allow the player to play the game multiple times, or the user can quit the application by entering a sentinel value. void displayChoice(int) The displayChoice function accepts an integer argument and displays rock, paper, or scissors. int getComputerChoice() This function returns the computer's game choice. It returns 1 for rock (via the ROCK constant), or 2 for paper (via the PAPER constant), or 3 for scissors (via the SCISSORS constant). int getUserChoice() This function displays a menu the user to select rock, paper, or scissors. The function then returns 1 for rock (via the ROCK constant), or 2 for paper (via the PAPER constant), or 3 for scissors (via the SCISSORS constant), or the user can enter a sentinel value: 4 to quit the application. void determineWinner(int, int) This function accepts the user's game choice and the computer's game choice as arguments and displays a message indicating the winner.
Explanation / Answer
Answer :
#include <iostream>
#include <cmath>
#include <cstdlib>
using namespace std;
int main(){
char ch;
int win = 0;
int tie = 0;
int lose = 0;
do{
int select;
cout << "-- Game On Rock, Paper, Scissors...Lets Rock ! --" << endl;
cout << "Type 1 for Rock, 2 for Paper, 3 for Scissors:" << endl;
cin >> select;
int num = rand() % 3 + 1;
cout << "The computer chose: " << num<< endl;
if(select== 1 && num == 1){
cout << "Rock meets Rock its a tie!" << endl;
tie++;
}
else if(select ==1 && num== 2){
cout << "Rock is covered by Paper the computer wins!." << endl;
lose++;
}
else if(select== 1 && num == 3){
cout << "Rock crushes Scissors you win!" << endl;
win++;
}
else if(select == 2 && num== 1){
cout << "Paper covers Rock you win!" << endl;
win++;
}
else if(select == 2 && num== 2){
cout << "Paper meets Paper its a tie!" << endl;
tie++;
}
else if(select== 2 && num== 3){
cout << "Paper is cut by Scissors the computer wins!" << endl;
lose++;
}
else if( select == 3 && num == 1){
cout << "Scissors are crushed by Rock computer wins!" << endl;
lose++;
}
else if( select == 3 && num == 2){
cout << "Scissors cuts Paper you win!" << endl;
win++;
}
else if(select == 3 && num== 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;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.