C++ program for calculating the average of scores
#include <iostream>
using namespace std;
const int n=5;//As per question only 5 test scores were there
int numbers[5];
void getscore(int i)//defining function for taking input
{
cin >> numbers[i];
while(numbers[i]<0 || numbers[i]>100)//score should be between 0 to 100
{
cout<<"\nThe number should be between 0 to 100\n";
cin>>numbers[i];
}
}
int main()//driver function
{
cout << "Enter 5 scores:\n";
for (int i = 0; i < n; i++)
{
getscore (i);//calling function each time for input
}
int s = 101;
double avg = 0;
for (int i = 0; i < n; i++)//loop for finding the smallest
{
s = numbers[i] < s ? numbers[i] : s;
}
for (int i = 0; i < n; i++) //loop for finding the Average
{
avg += numbers[i];
}
avg -= s;
avg /= 4;
cout << "Average of the four scores are: " << avg<< endl;//printing the output
return 0;
}
Output
Enter 5 scores:
4
5
6
7
8
Average of the four scores are: 6.5