Answer to Question #287981 in C++ for nana

Question #287981

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!)


1
Expert's answer
2022-01-16T13:04:21-0500




#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;
}

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