64 642
Assignments Done
99,2%
Successfully Done
In September 2018

Answer to Question #5623 in C++ for Tstrother

Question #5623
Write a program that calculates the class average of student grades using sentinel-controlled repetition (while loop), which will process an arbitrary number of grades. The user enters a series of grades, then -1 when finished.
Expert's answer

# include<iostream.h>
# include<conio.h>

int grades[1000];
int i, N, answer;
double average;

void main(){
N=0;
while (answer>=0){
& cout<<"Enter student's grade or -1 to finish: ";
& cin>>answer;
& if (answer>=0) { grades[N] = answer; N++; }
& if (answer<0) break;
}
average = 0;
for (i=0;i<N;i++) average = average + grades[i];
average = average/N;
cout<<"Average number is "<<average<<"\r\n";
getch();
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions