Average

Description:

Write a function calculateAverage() which takes four int arguments which are marks for four courses in the semester and returns their average as a float. The calculateAverage() function should take only valid range for marks which is between 0 - 100. If the marks are out of range throw an OutOfRangeException as shown below - define this exception as a class. Enter marks for subject 1:23 Enter marks for subject 2:56 Enter marks for subject 3:104 marks out of range Test Case 1 Input (stdin) 5 45 84 98 89 63 Expected Output marks in range Test Case 2 Input (stdin) 5 45 84 135 63 23 Expected Output marks out of range

Program :

#include <iostream>

using namespace std;

int main()

{

int n,i,sum=0,a[50],o=0;

  cin>>n;

  for(i=0;i<n;i++)

  {

    cin>>a[i];

    if(a[i]>100 || a[i]<0)

      o++;

  sum=sum+a[i];

  }

  if(o!=0)

    cout<<"marks out of range";

  else

    cout<<"marks in range";

return 0;

}