Write a program that calcuates the average of a group of 5 test scores, where th
ID: 3635674 • Letter: W
Question
Write a program that calcuates the average of a group of 5 test scores, where the lowest score in the group is dropped. Your program should use the following functions:getScore( ) should ask the user for a test score, store it in a reference variable, and validate it. This function should be called by main once for each of the five scores.
calcAverage( ) should calculate and display the average of the four highest scores. This function hould be called just once by main, and should be passed the five scores.
findLowest( ) should find and return the lowest of the five scores passed to it. It should be called by cacAverage, which uses the function to determin which of the five scores to drop.
Input Validation: So not accept test scores lower than 0 or higher than 100
Explanation / Answer
please rate - thanks
you said nothing about arrays so I didn't use any. I can change that if needed
please rate - thanks
#include <iostream>
using namespace std;
void getScore(int&);
void calcAverage(int,int,int,int,int);
int findLowest(int,int,int,int,int);
int main()
{int n1,n2,n3,n4,n5;
getScore(n1);
getScore(n2);
getScore(n3);
getScore(n4);
getScore(n5);
calcAverage(n1,n2,n3,n4,n5);
system("pause");
return 0;
}
void getScore(int& num)
{do
{cout<<"enter a number: ";
cin>>num;
if(num<0||num>100)
cout<<"number out of range-try again ";
}while(num<0||num>100);
return;
}
void calcAverage(int n1,int n2,int n3,int n4,int n5)
{double average;
int low,total;
low=findLowest(n1,n2,n3,n4,n5);
total=n1+n2+n3+n4+n5-low;
average=total/4.;
cout<<"The average of the top 4 grades is "<<average<<endl;
return;
}
int findLowest(int n1,int n2,int n3,int n4,int n5)
{int low;
low=n1;
if(n2<low)
low=n2;
if(n3<low)
low=n3;
if(n4<low)
low=n4;
if(n5<low)
low=n5;
return low;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.