Advertisement
Guest User

Untitled

a guest
Mar 28th, 2020
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main()
  4. {
  5. float average, score_amount, i, score_total;
  6.  
  7. score_amount = 0;
  8. score_total = 0;
  9.  
  10. printf("The program calculates the average of scores you enter.\n");
  11. printf("End with a negative integer.\n");
  12.  
  13. do
  14. {
  15. printf("Enter score (4-10):");
  16. scanf("%f", &i);
  17.  
  18. score_total = score_total + i;
  19. score_amount = score_amount + 1;
  20.  
  21.  
  22. if(i < 0)
  23. {
  24. score_amount = score_amount -1;
  25. score_total = score_total - i;
  26. average = score_total / score_amount;
  27. printf("You entered %.0f scores.\n", score_amount);
  28. printf("Average score: %.2f", average);
  29. }
  30. }
  31. while(i >= 0);
  32.  
  33.  
  34. return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement