Write a complete C++ program that uses a while loop to perform the following: • Input scores for CS411 exam for the students enrolled in CS411 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. (Please do not include array. Thank you so much!)
#include <iostream>
using namespace std;
int main() {
int n;
int mark;
int totalScores=0;
int highestScore=-1;
int lowestScore=1000;
double averageScores;
int earnedScoresAbove50Marks=0;
int earnedScoresBelow50Marks=0;
//User has to input number of students.
cout<<"Enter the number of students: ";
cin>>n;
for(int k=0;k<n;k++){
cout<<"Enter the mark of the student "<<(k+1)<<": ";
cin>>mark;
totalScores+=mark;
if(mark>highestScore){
highestScore=mark;
}
if(mark<lowestScore){
lowestScore=mark;
}
averageScores=(double)totalScores/(double)n;
if(mark>=50){
earnedScoresAbove50Marks++;
}else{
earnedScoresBelow50Marks++;
}
}
//Find and display the total of the scores.
cout<<"\n\nThe total of the scores: "<<totalScores<<"\n";
//Find and display the highest and lowest scores.
cout<<"The highest score: "<<highestScore<<"\n";
cout<<"The lowest score: "<<lowestScore<<"\n";
//Calculate and display the average of the scores.
cout<<"The average of the scores: "<<averageScores<<"\n";
//Count and display how many students earned scores above and equal to 50 marks.
cout<<"Students earned scores above and equal to 50 marks: "<<earnedScoresAbove50Marks<<"\n";
//Count and display how many students earned scores below 50 marks.
cout<<"Students earned scores below 50 marks: "<<earnedScoresBelow50Marks<<"\n";
system("pause");
return 0;
}
Comments
Leave a comment