Get the FREE certificate on C, C++, Java, Python, Perl, PHP, SQL, Linux & Javascript!  

CppBuzz.com
  
Home C C++ Java Python Perl PHP Spring SQL Javascript Linux

You are here : Home » Solved Programs on C++ » C++ program to find avg of top 4 score

C++ program to find avg of top 4 score

#include<iostream>
using namespace std;

void getScore(float &score)
{
cout<<"\n Enter test score : ";
cin>>score;
}

float  findLowest(float arr[])
{
float lowest = arr[0];

for(int i = 1 ; i<5; i++)
{ 
 if(lowest>arr[i])
 {
     lowest = arr[i];
 }
}

cout<<"\n Lowest is : "<<lowest;

return lowest;
}

void calcAverage(float arr[]){

float lowest = findLowest(arr);
float avg = 0;

for(int i = 0; i< 5; i++)
{
if(arr[i] !=  lowest)
avg = avg + arr[i];
}
avg = avg/4;
cout<<"\n Average is : "<< avg;
}

int main()
{
float arr[5];
for(int i = 0; i< 5; i++)
{
   getScore(arr[i]);
}

calcAverage(arr);
return 0;
}