Advertisement
keeyres

forloop3

Dec 1st, 2015
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5. const int scores = 4;
  6. const int students = 10;
  7. int i, j;
  8. double grade, total, average;
  9. for (i = 1; i <= students; i++) // start of outer loop
  10. {
  11. total = 0; // clear total for this student
  12. for (j = 1; j <= scores; j++) // start of inner loop
  13. {
  14. printf ("\n Exam score? ");
  15. scanf ("%d", &grade);
  16. total = total + grade; // add the grade to the total
  17. } // end of inner for loop
  18. average = total / scores; // calculate the average
  19. printf ("\n Average of student no.#");
  20. printf ("%d", i);
  21. printf (" is ");
  22. printf ("%d", average);
  23. printf ("\n \n");
  24. } // end of outer for loop
  25. return 0;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement