Nested Loop Handout f2007

Nested Loop Handout f2007 - Nested Loop Example A int...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Nested Loop Example A int main() { int numStudents, // Number of students numTests, // Number of tests per student total; // Accumulates total score for each student double average; // Average test score for each student cout << "This program averages test scores.\n" ; cout << "How many students are there? " ; cin >> numStudents; cout << "How many test scores does each student have? " ; cin >> numTests; cout << endl; for ( int student = 1; student <= numStudents; student++) // Outer loop { total = 0; for ( int test = 1; test <= numTests; test++) // Inner loop { int score; cout << "Enter score " << test << " for " << "student " << student << ": " ; cin >> score; total += score; } // End of inner loop average = total / numTests; cout << "The average for student " << student; cout << " is " << average << ".\n\n" ; } // End of outer loop return 0; }
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Nested Loop Example B int main() { int numStudents, // Number of students numTests, // Number of tests per student total; // Accumulates total score for each student
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/18/2008 for the course CS 201 taught by Professor Conway during the Fall '07 term at Bowling Green.

Page1 / 4

Nested Loop Handout f2007 - Nested Loop Example A int...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online