What's new

Closed C++ problem

Status
Not open for further replies.
Code:
#include <stdio.h>

int main() {
   float grade=0,sum=0,ave=0;
   int count=0;

   while(1) {
       printf("Enter grade or a negative number to exit: ");
       scanf("%f",&grade);
       if(grade<0) {
           break;
       }
       sum+=grade; 
       count++; 
       ave=sum/count;
       printf("total: %.2f ",sum);
       printf("count: %d ",count);
       printf("average: %.2f\n",ave);
   }
 
   printf("bye!\n");
 
   return 0;
}
 
Status
Not open for further replies.

Similar threads

Back
Top