Answer to Question #220344 in C++ for Qihah

Question #220344

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. 


1
Expert's answer
2021-07-25T08:39:13-0400
#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;
    
}


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS