Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please, using C, not C+ or C++. Thanks Files to submit: grade_need.c Time it too

ID: 3594102 • Letter: P

Question

Please, using C, not C+ or C++. Thanks

Files to submit: grade_need.c

Time it took Matthew to Complete: 15 mins

Requriements

Program must compile with both -Wall and -Werror options enabled

Submit only the files requested

Use doubles to store real numbers

Print all doubles to 2 decimal points unless stated otherwise

Restrictions

No global variables may be used

Your main function may only declare variables and call other functions

Description

Write a program called grade_need.c that calcualtes the minimum percent needed on the final to achieve the desired grade. If the desired grade cannot be achieved because the person cannot score low or high enough on the final to get the desired grade, your program should tell them so.

Requirements

Your program should be able to accept both lowercase and uppercase letters for the letter grade desired

Assumptions

Input is NOT guarenteed to be valid Some examples of improprer input are

Incorrectlly formatted input

Incorrect letter grades desired

If invalid input is received, your program should report it and terminate

You'll find the exit function in stdlib.h for doing this. Make sure to only use 0 with exit and no other value.

Wait until we cover how to handle invalid input in class before dealing with this part of the problem

Examples

Example 1

Enter the grade you want in the class: B
Enter your current percent in the class: 75
Enter the weight of the final: 20
You need a grade of at least 100.00% on the final to get a B in
the class.

Example 2

Enter the grade you want in the class: b
Enter your current percent in the class: 75
Enter the weight of the final: 25
You need a grade of at least 95.00% on the final to get a b in
the class.

Example 3

Enter the grade you want in the class: A
Enter your current percent in the class: 85
Enter the weight of the final: 20
You cannot get a A in the class because you would need to score
at least 110.00% on the final.

Example 4

Enter the grade you want in the class: F
Enter your current percent in the class: 90
Enter the weight of the final: 10
You cannot score low enough on the final to get a F in the
class.

Example 5

Enter the grade you want in the class: H
Unknown Grade Received: H. Ending program.

Example 6

Enter the grade you want in the class: C
Enter your current percent in the class: bob
Invalid formatting. Ending program.

Example 7

Enter the grade you want in the class: A
Enter your current percent in the class: 87
Enter the weight of the final: !75
Invalid formatting. Ending program.

Example 8

Enter the grade you want in the class: B
Enter your current percent in the class: 12G
Invalid formatting. Ending program.

Example 9

Enter the grade you want in the class: B
Enter your current percent in the class: -35
The number you last entered should have been positive. Ending
program.

Grade Minimum Percent Needed A 90% B 80% C 70% D 60% F 0%

Explanation / Answer

//grade finction calculate the grade as per required formats
#include<stdio.h>

int grade();
void print_grade(float requiredGrade,char expectedGrade);

int main() {
grade();
}

int grade()
{
char expectedGrade;
float currentPercent,weight,requiredGrade;

printf("Enter the grade you want in the class: ");
scanf(" %c",&expectedGrade);
if(expectedGrade != 'A' && expectedGrade !='a' && expectedGrade != 'B' && expectedGrade != 'b' && expectedGrade != 'C' && expectedGrade !='c' && expectedGrade != 'D' && expectedGrade != 'd' && expectedGrade !='F' && expectedGrade !='f')
{
printf("Unknown Grade Received ");
return 0;
}

printf("Enter your current percent in the class: ");
if (scanf("%f",&currentPercent) != 1)
{
printf("Invalid Format ");
return 0;

}

if(currentPercent<0) {
printf("The number you last entered should have been positive. ");
return 0;
}

printf("Enter the weight of the final: ");
scanf("%f",&weight);

if(weight < 0) {
printf("The number you last entered should have been positive. ");
return 0;
}

weight = weight/100;

if(expectedGrade == 'A' || expectedGrade == 'a') {
requiredGrade = (90 - (currentPercent*((1-weight)/1))) / weight;
print_grade(requiredGrade,expectedGrade);
}

else if(expectedGrade == 'B' || expectedGrade == 'b') {
requiredGrade = (80 - (currentPercent*(1-weight))) / weight;
print_grade(requiredGrade,expectedGrade);

}

else if(expectedGrade == 'C' || expectedGrade == 'c') {
requiredGrade = (70 - (currentPercent*((1-weight)/1))) / weight;
print_grade(requiredGrade, expectedGrade);
}

else if(expectedGrade == 'D' || expectedGrade == 'd') {
requiredGrade = (60 - (currentPercent*((1-weight)/1))) / weight;
print_grade(requiredGrade, expectedGrade);
}

else if(expectedGrade == 'F' || expectedGrade == 'f')
printf("You cannot score low enough on the final to get a F in the class. ");

return 0;
}

void print_grade(float requiredGrade,char expectedGrade)
{
if(requiredGrade<=100)
printf("You need a grade of at least %.2f on the final to get a %c in the class. ",requiredGrade,expectedGrade);
else
printf("You cannot get a %c in the class because you would need to score at least %.2f on the final. ",expectedGrade,requiredGrade);
}