🔒 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.

About this Thread

  • 40
    Replies
  • 2K
    Views
  • 9
    Participants
Last reply from:
siesta

Trending Topics

Online now

Members online
1,050
Guests online
926
Total visitors
1,976

Forum statistics

Threads
2,278,954
Posts
28,987,096
Members
1,226,677
Latest member
thecatloverl
Back
Top