fork download
  1. #include <stdio.h>
  2. int main ()
  3. {
  4. /* variable definition: */
  5. char StudentName[100];
  6. float ExamValue, Sum, Avg;
  7. int students,howmanystudents,exams;
  8.  
  9. // Loop through unlimited Students
  10.  
  11. howmanystudents = 0;
  12.  
  13. while (howmanystudents >= 0)
  14. {
  15. printf("How many students grades would you like to average?\n");
  16. scanf("%d", &howmanystudents);
  17.  
  18. if(howmanystudents >= 0)
  19. break;
  20.  
  21. }
  22.  
  23. students = 0;
  24.  
  25. while (students = howmanystudents)
  26. {
  27. if (students >= 0)
  28. {
  29. for (students=0; students < howmanystudents; students++)
  30. {
  31. // reset Sum to 0
  32. Sum =0.0;
  33. printf("Enter Student Name \n");
  34. scanf("%s", StudentName);
  35.  
  36. // Nested Loop for Exams
  37. for (exams=0; exams < 3; exams++)
  38. {
  39. printf ("Enter exam grade: \n");
  40. scanf("%f", &ExamValue);
  41. Sum += ExamValue;
  42. }
  43. }
  44. Avg = Sum/3.0;
  45. printf( "Average for %s is %f\n",StudentName,Avg);
  46. }
  47. if (students < 0)
  48. {
  49. printf("Please enter the number of students/exams you would like averaged.\n");
  50. break;
  51. }
  52. }
  53. return 0;
  54. }
Success #stdin #stdout 0s 9432KB
stdin
young 1 2 3
blood 2 3 4
stdout
How many students grades would you like to average?