Q5: (GPA Calculator) (20 points): Figure 3.8 in the textbook provides code that
ID: 3744809 • Letter: Q
Question
Q5: (GPA Calculator) (20 points): Figure 3.8 in the textbook provides code that allows a user to enter a li of grades in number format, and then it displays the letter grade for the number and calculates the averag grade for the class. Modify this code so that it becomes a GPA calculator. You will find the nested if.else ifcod example in the textbook on page 78 that also uses numerical grades to be very useful. Merge the two code examples of the textbook, adding some prompts for the amount of semester hours per grade, and some variables to keep up with total GPA points earned and total semester hours taken. Use the following chart o GPA point values: Number Grade Letter Grade GPA Points per Semester Hour 93-100 90-92 86-89 83 85 80-82 76-79 73-75 70-72 66-69 63 -66 4.00 3.75 3.25 3.00 2.75 2.25 2.00 1.75 1.25 1.00 0.75 0.00 A- Bt B- C+ D+ 60 62Explanation / Answer
#include <stdio.h>
int main()
{
int x = 1, grade = 0, hours = 0, totalHours = 0, totalGPA = 0;
float GPA = 0;
do
{
printf(" Enter grade, -1 to end:");
scanf("%d", &grade);
if (grade > 0)
{
printf(" Enter the Semester Hours for this course:");
scanf("%d", &hours);
}
printf(" ");
if (grade <= 100 && grade >= 93)
{
totalHours = totalHours + hours;
GPA = GPA + (hours * 4);
printf("A Cumulative Semester Hours: %d ", totalHours);
printf("Cumulative GPA points: %1.3f ", GPA);
}
else if (grade <= 92 && grade >= 90)
{
totalHours = totalHours + hours;
GPA = GPA + (hours * 3.75);
printf("A- Cumulative Semester Hours: %d ", totalHours);
printf("Cumulative GPA points: %1.3f ", GPA);
}
else if (grade <= 89 && grade >= 86)
{
totalHours = totalHours + hours;
GPA = GPA + (hours * 3.25);
printf("B+ Cumulative Semester Hours: %d ", totalHours);
printf("Cumulative GPA points: %1.3f ", GPA);
}
else if (grade <= 85 && grade >= 83)
{
totalHours = totalHours + hours;
GPA = GPA + (hours * 3);
printf("B Cumulative Semester Hours: %d ", totalHours);
printf("Cumulative GPA points: %1.3f ", GPA);
}
else if (grade <= 82 && grade >= 80)
{
totalHours = totalHours + hours;
GPA = GPA + (hours * 2.75);
printf("B- Cumulative Semester Hours: %d ", totalHours);
printf("Cumulative GPA points: %1.3f ", GPA);
}
else if (grade <= 79 && grade >= 76)
{
totalHours = totalHours + hours;
GPA = GPA + (hours * 2.25);
printf("C+ Cumulative Semester Hours: %d ", totalHours);
printf("Cumulative GPA points: %1.3f ", GPA);
}
else if (grade <= 75 && grade >= 73)
{
totalHours = totalHours + hours;
GPA = GPA + (hours * 2);
printf("C Cumulative Semester Hours: %d ", totalHours);
printf("Cumulative GPA points: %1.3f ", GPA);
}
else if (grade <= 72 && grade >= 70)
{
totalHours = totalHours + hours;
GPA = GPA + (hours * 1.75);
printf("C- Cumulative Semester Hours: %d ", totalHours);
printf("Cumulative GPA points: %1.3f ", GPA);
}
else if (grade <= 69 && grade >= 66)
{
totalHours = totalHours + hours;
GPA = GPA + (hours * 1.25);
printf("D+ Cumulative Semester Hours: %d ", totalHours);
printf("Cumulative GPA points: %1.3f ", GPA);
}
else if (grade <= 63 && grade >= 66)
{
totalHours = totalHours + hours;
GPA = GPA + (hours * 1);
printf("D Cumulative Semester Hours: %d ", totalHours);
printf("Cumulative GPA points: %1.3f ", GPA);
}
else if (grade <= 62 && grade >= 60)
{
totalHours = totalHours + hours;
GPA = GPA + (hours * 0.75);
printf("D- Cumulative Semester Hours: %d ", totalHours);
printf("Cumulative GPA points: %1.3f ", GPA);
}
else if (grade < 60 && grade > 0)
{
totalHours = totalHours + hours;
GPA = GPA + (hours * 0.00);
printf("F Cumulative Semester Hours: %d ", totalHours);
printf("Cumulative GPA points: %1.3f ", GPA);
}
else
{
printf("GPA is %1.3f", GPA / totalHours);
}
} while (grade >= 60 && grade <= 100);
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.