Login
Order Now
Support
theprogrammingassignmenthelp

Write A Program That Will Calculate A Student’s Quiz Average

  • 4th Sep, 2020
  • 14:46 PM

Programming Assignment Question - Write A Program That Will Calculate A Student’s Quiz Average.

 

Programming Assignment Solution -

Quiz Average Letter Grade

Greater than or equal to 90 A
Greater than or equal to 80 B
Greater than or equal to 70 C
Greater than or equal to 60 D
Otherwise F
The input prompts and output statements must match the sample execution below.

Sample Executions:

Quiz Calculator
How many quizzes: 4
Enter quiz 1 grade: 90
Enter quiz 2 grade: 100
Enter quiz 3 grade: 87
Enter quiz 4 grade: 85
Your quiz average is 90.500000, A
Quiz Calculator
How many quizzes: 2
Enter quiz 1 grade: 85
Enter quiz 2 grade: 75
Your quiz average is 80.000000, B

Sample Executions:
Quiz Calculator
How many quizzes: 3
Enter quiz 1 grade: -10
I think you made a mistake!
Enter quiz 1 grade: 10
Enter quiz 2 grade: 195
I think you made a mistake!
Enter quiz 2 grade: 95
Enter quiz 3 grade: 40
Your quiz average is 48.333332, F

Solution 

netIDprog4.c 

#include <stdio.h>

int main() {

int quizzes; //to store total quiz

floattotalScore = 0.0, score; //toal score and individual score

// read quizzes

printf(“How many quizzes: “);

scanf(“%d”, &quizzes);

// for each quiz

for (int i = 1; i <= quizzes; ++i) {

do {

// read score

printf(“Enter quiz %d grade: “, i);

scanf(“%f”, &score);

if (score < 0 || score > 100) { //if invalid

printf(“I think you made a mistake!\n\n”);

}

} while (score < 0 || score > 100); //continue while invalid

// add to toal score

totalScore += score;

}

//calculate average

float average = totalScore / quizzes;

// calculate grade

char grade;

if (average >= 90)

grade = ‘A’;

else if (average >= 80)

grade = ‘B’;

else if (average >= 70)

grade = ‘C’;

else if (average >= 60)

grade = ‘D’;

else

grade = ‘F’;

//rpint result

printf(“Your quiz average is %f, %c”, average, grade);

}

Share this post