Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program that calculates the average of a group of test scores, where the lowest score in the group is dropped. It should use

Write a program that calculates the average of a group of test scores, where the lowest score in the group is dropped. It should use the following functions: void getScore() should ask the user for a test score, store it in a reference parameter variable, and validate it. This function should be called by main once for each of the five scores to be entered. void calcAverage() should calculate and display the average of the four highest scores. This function should be called just once by main, and should be passed the five scores. int findLowest() should find and return the lowest of the five scores passed to it. It should be called by calcAverage, which uses the function to determine which of the five scores to drop. Input Validation: Do not accept test scores lower than 0 or higher than 100.

I have the code written, but for some reason it does not display the lowest score or average. Here is the code:

//I just include all of these simply because I don't know which ones will be used #include #include #include #include #include using namespace std;

//These are the function prototypes being used for this program void getScore(int test1, int test2, int test3, int test4, int test5); void calcAverage(int test1, int test2, int test3, int test4, int test5, int lowScore); int findLowest(int test1, int test2, int test3, int test4, int test5, int lowScore);

int main() { int test1, test2, test3, test4, test5, lowScore; //These are the two functions that are to be called once in the main int function. //The int findLowest function is imbedded in the calcAverage function. getScore(test1, test2, test3, test4, test5); calcAverage(test1, test2, test3, test4, test5, lowScore); system("pause"); return 0; } void getScore(int test1, int test2, int test3, int test4, int test5) { //In these sequences, the five test scores will be accounted for. //The while statement is also utilized. If a score is not within the range of //0 and 100, and error message will appear, and the user will need to input a valid score. cout << "Please enter a test score between 0 and 100: "; cin >> test1; while (test1 < 0 || test1 > 100) { cout << "INVALID RESPONSE!! Please enter number between 0 and 100: "; cin >> test1; } cout << "Please enter a test score between 0 and 100: "; cin >> test2; while (test2 < 0 || test2 > 100) { cout << "INVALID RESPONSE!! Please enter number between 0 and 100: "; cin >> test2; } cout << "Please enter a test score between 0 and 100: "; cin >> test3; while (test3 < 0 || test3 > 100) { cout << "INVALID RESPONSE!! Please enter number between 0 and 100: "; cin >> test3; } cout << "Please enter a test score between 0 and 100: "; cin >> test4; while (test4 < 0 || test4 > 100) { cout << "INVALID RESPONSE!! Please enter number between 0 and 100: "; cin >> test4; } cout << "Please enter a test score between 0 and 100: "; cin >> test5; while (test5 < 0 || test5 > 100) { cout << "INVALID RESPONSE!! Please enter number between 0 and 100: "; cin >> test5; } }

void calcAverage(int test1, int test2, int test3, int test4, int test5, int lowScore) { //The findLowest function is called in this instance to declare the lowest score lowScore = findLowest(test1, test2, test3, test4, test5, lowScore); // The sum of the test scores is found by adding all of the tests, then subtracting the lowest score from the bunch int sum = test1 + test2 + test3 + test4 + test5 - lowScore; //The average score is found by taking the sum and dividing it by 4, //signifying the four highest test scores. double avgScore = sum / 4.0; cout << "The average of the scores is " << avgScore << "."; } int findLowest(int test1, int test2, int test3, int test4, int test5, int lowScore) { //In this function, the lowest score out of all the tests will be found. //Continuous if statements are utilized in the case that the next test score is //indeed the lowest test score out of the rest. lowScore = test1; if (test2 <= lowScore){ lowScore = test2; } if (test3 <= lowScore){ lowScore = test3; } if (test4 <= lowScore){ lowScore = test4; } if (test5 <= lowScore){ lowScore = test5; } //The lowest test score is intended to be displayed once going through all of the if statements. cout << "The lowest score is " << lowScore << ". "; //The lowest score is then returned, thus ending the function. return lowScore; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Samsung Galaxy S23 Ultra Comprehensive User Manual

Authors: Leo Scott

1st Edition

B0BVPBJK5Q, 979-8377286455

More Books

Students also viewed these Databases questions