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

Unit 2 covered Chapters 4-7. Chapter 4 covered selection statements which includ

ID: 642706 • Letter: U

Question

Unit 2 covered Chapters 4-7. Chapter 4 covered selection statements which included if, if-else, and switch statements. Chapter 5 covered basic loop structures, such as while, for and do-while statements Chapters 6 and 7 covered functions. Refer to "What to Turn In" for specific details on what should be turned in and how to turn in your project.

Write a C program that accepts numeric grades and then displays the average of the grades entered. Sample output:

To stop entering grades, type in any negative number.
Enter a grade: 98.4
Enter a grade: 99
Enter a grade: -1

The total of the grades is 197.40
The average of the grades is 98.70

Explanation / Answer

#include <iostream>

using namespace std;

int main() {

// your code goes here

int sum=0,avg=0,grade=0;

int count=0;

cout<< "To stop entering grades, type in any negative number";

do

{

cout<<"Enter a grade:" ;

cin>>grade;

sum=sum+grade;

count++;

}while(grade>0);

avg=sum/count;

cout<< "The total of the grades is" << sum;

cout << "The average of the grades is" << avg;

return 0;

}