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.
1
Expert's answer
2011-12-15T07:39:56-0500

# 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 the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS