L07_loops - Loops Loops EECS 183 University of Michigan...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Loops Loops EECS 183 University of Michigan Lecture 06 We We Often Want to Repeat Things • Take 10 steps forward… • Drive West until you reach the Mississippi River… • Sleep until the alarm clock goes off • Great for “counting” EECS 183 University of Michigan Lecture 06 while while for • three items for each type of of loop • initialize loop control variable variable • condition on loop • update EECS 183 University of Michigan Lecture 06 int start = 5; // initialization int end = 20; // initialization while(start <= end) { // conditional cout << start<<" "; start++; // update } void printAll(int start, int end) { while (start <= end) { cout << start << " " ; start++; } EECS 183 University of Michigan Lecture 06 write the function void printEven (int start, int end); that will print even numbers between 'start' and 'end' EECS 183 University of Michigan Lecture 06 write the function void printIfEqualUnitDigit (int start, int end, int digit); that will print all numbers between 'start' and 'end' if the units digit is equal to 'digit' EECS 183 University of Michigan Lecture 06 re-write the function used in L05_average.cpp int getScore("string prompt"); calls: int x = getScore("first number: "); int y = getScore("second number: "); int z = getScore("third number: "); where this function will guarantee that a valid number is returned valid number is any number between 0 and 100 inclusive it will print an error message if any invalid input is entered, and re-prompt EECS 183 University of Michigan Lecture 06 ...
View Full Document

This note was uploaded on 02/12/2010 for the course EECS 183 taught by Professor Dorf during the Fall '08 term at University of Michigan.

Page1 / 7

L07_loops - Loops Loops EECS 183 University of Michigan...

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

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