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

1. Write a program that reads in a list letter grades and class hours via the ke

ID: 3531918 • Letter: 1

Question

1. Write a program that reads in a list letter grades and class hours via the keyboard and reports the GPA for the given grades. Recall that grades are weighted as:

Grade

Weight

A

4.0

B

3.0

C

2.0

D

1.0

F

0.0

Grades will be entered as A, B, C, D or F, and the user will indicate that he's done by entering Q. Lower case versions of all of these must be accepted as well, but you MAY assume that invalid data is never entered.

Example run. User input appears in red

Input letter grade and hours (or Q to quit): A 3

Input letter grade and hours (or Q to quit): b 3

Input letter grade and hours (or Q to quit): a 1

Input letter grade and hours (or Q to quit): C 5

Input letter grade and hours (or Q to quit): B 3

Input letter grade and hours (or Q to quit): Q

GPA = 2.93333

Grade

Weight

A

4.0

B

3.0

C

2.0

D

1.0

F

0.0

Explanation / Answer

char g;

int h;

hsum=0;

gpasum=0;

while(c!='Q' || c=='q')

{

printf("Enter grade");

scanf("%c",g);

printf(" Enter hours");

scanf("%d",h);


if(c=='A' || c=='a')

{

gpasum += 4*h;

hsum+=h;

}

else if(c=='B' || c=='b')

{

gpasum += 3*h;

hsum+=h;

}

else if(c=='C' || c=='c')

{

gpasum += 2*h;

hsum+=h;

}

else if(c=='D' || c=='d')

{

gpasum += 1*h;

hsum+=h;

}

else if(c=='F' || c=='f')

{

gpasum += 0*h;

hsum+=h;

}

printf(" Your GPA is %f", gpasum/hsum);


}