Answer to Question #289919 in C++ for Mum

Question #289919

Array size is 100

- gets the best score out of all the inputted grades and assigned grades based on the following scheme:

Grade is A if score is > = best - 10;

Grade is B if score is > = best - 20;

Grade is C if score is > = best - 30;

Grade is D if score is > = best - 40;

Grade is F otherwise.

Sample:

Enter the number of students: 4

Enter 4 scores: 40 55 70 58

Student 0 score is 40 and grade is C

Student 1 score is 55 and grade is B

Student 2 score is 70 and grade is A

Student 3 score is 58 and grade is B


1
Expert's answer
2022-01-23T13:38:28-0500
#include <iostream>
#include <string>




using namespace std;




char getGrade(int bestScore, int score){
	//Grade is A if score is > = best - 10;
	if(score>= bestScore - 10){
		return 'A';
	}
	//Grade is B if score is > = best - 20;
	if(score>= bestScore - 20){
		return 'B';
	}
	//Grade is C if score is > = best - 30;
	if(score>= bestScore - 30){
		return 'C';
	}
	//Grade is D if score is > = best - 40;
	if(score>= bestScore - 40){
		return 'D';
	}
	//Grade is F otherwise.
	return 'F';
}


int main(void){


	int scores[100];
	int n;
	int bestScore=0;
	cout<<"Enter the number of students: ";
	cin>>n;
	cout<<"Enter 4 scores: ";
	for (int i = 0; i < n; i++)
	{
		cin>>scores[i];
		if(scores[i]>bestScore){
			bestScore=scores[i];
		}
	}
	for (int i = 0; i < n; i++)
	{
		cout<<"Student "<<i<<" score is "<<scores[i]<<" and grade is "<<getGrade(bestScore,scores[i])<<"\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

LATEST TUTORIALS
New on Blog