// Author: Keith Shomper // Date: 9/26/03 // Purose; To demonstrate the for loop by finding the largest of a group of // numbers #include using namespace std; int main() { int howMany; float num, largest; // prompt the user for the amount of numbers to compare cout << "How many numbers do you want to compare? "; cin >> howMany; // Note the "I", "T" and "M" of ITEM all happen in the next line for (int i = 1; i <= howMany; ++i ) { // get the nth number // ** NOTE ** can yo make this prompting code better, so that it handles // more cases??? cout << "Please enter the " << i; switch (i) { case 1: cout << "st"; break; case 2: cout << "nd"; break; case 3: cout << "rd"; break; default: cout << "th"; } cout << " number: "; cin >> num; // find the largest number we've seen so far if (i == 1) largest = num; else if (num > largest) largest = num; } // report the largest number seen cout << "The largest number you gave is " << largest << endl; return 0; }