In: Computer Science
Complete the following assignment in C programming language.
1. Declare the following float variables:
-Maximum exam score, user's exam score, and percentage.
2. Ask the user to input data into your variables, such as:
-"What is the max score of your exam:"
-"What was your score:"
3. Use if statements to validate user inputs. For example, score received should not be more than maximum possible score.
-Display an error message when the user enters invalid data.
-You can restart the program if use enters invalid input by pressing the RESET button on the processor board.
4. Build your Software logic to calculate the percentage and the letter grade.
-Hint: Store your letter grade to a char variable.
-Hint: Use if and else if statements. Scan from A to D leaving F to else statement.
5. Print out summary for the user:
-If the user's grade is either B, C, or D, print-out how many percent points the user is away from the next letter grade.
-Hint: (Score % 10) will tell you the remainder. If grade is B, C or D, calculate the remainder and subtract from 10.
-Example print-out:
-"You scored a B, and you were 3 percent away from the next letter grade."
Thanks for the question.
Below is the code you will be needing Let me know if you have
any doubts or if you need anything to change.
Thank You !!
===========================================================================
#include<stdio.h>
int main(){
float max_exam_score;
float user_exam_score;
float percentage;
printf("What is the max score of your exam: ");
scanf("%f",&max_exam_score);
printf("What was your score: ");
scanf("%f",&user_exam_score);
if(user_exam_score<=max_exam_score &&
user_exam_score>=0 && max_exam_score>=0){
percentage =
100.0*user_exam_score/max_exam_score;
if (percentage>=90){
printf("You
scored a A\n");
}else if(percentage>=80){
int away = 10 -
int(percentage)%10;
printf("You
score a B, and you were %d percent away from the next letter
grade.\n",away);
}
else if (percentage>=70){
int away = 10 -
int(percentage)%10;
printf("You
score a C, and you were %d percent away from the next letter
grade.\n",away);
}else if (percentage>=60){
int away = 10 -
int(percentage)%10;
printf("You
score a D, and you were %d percent away from the next letter
grade.\n",away);
}else{
printf("You
scored a F.\n");
}
}else{
printf("ERROR: Invalid Data
provided.\n");
}
}
======================================================================