Write a complete C++ program that uses a while loop to perform the following: ï‚· Input scores for CSC126 exam for the students enrolled in CSC126 course. User has to input number of students. ï‚· Find and display the total of the scores. ï‚· Find and display the highest and lowest scores. ï‚· Calculate and display the average of the scores. ï‚· Count and display how many students earned scores above and equal to 50 marks. ï‚· Count and display how many students earned scores below 50 marks.Â
#include <iostream>
using namespace std;
int getMin(int arr[], int n)
{
return (n == 1) ? arr[0] : min(arr[0],
getMin(arr + 1, n - 1));
}
int main() {
int i = 0;
int total = 0;
int above = 0;
int below = 0;
int max, min;
int n;
cout<<"Enter the number of students\n";
cin>>n;
int arr[n];
while (i<n){
cout<<"Enter mark "<<i + 1<<"\t";
cin>>arr[i];
i++;
}
int x = 0;
while(x<n){
total += arr[x];
x++;
}
cout<<total<<endl;
max = arr[0];
while (i<n){
total += arr[i];
if(arr[i] > max){
max = arr[i];
}
i++;
}
int m = 0;
while(m<n){
if(arr[m]>=50){
above++;
}
else{
below++;
}
m++;
}
cout<<"\nTotal scores\t"<<total;
cout<<"\nThe highest score\t"<<max;
cout<<"\nThe lowest score\t"<<getMin(arr,n);
cout<<"\nAverage of scores\t"<<total/n;
cout<<"\nAbove 50\t"<<above;
cout<<"\nBelow 50\t"<<below;
}
Comments
Leave a comment