{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# homework2 - 4.11 1 if age >= 65 cout <"Age is greater than...

This preview shows pages 1–5. Sign up to view the full content.

4.11 1. if ( age >= 65 ) cout << "Age is greater than or equal to 65" << endl; else cout << "Age is less than 65” << endl; 2. if ( age >= 65 ) cout << "Age is greater than or equal to 65" << endl; else cout << "Age is less than 65” << endl; 3. int x, total = 1; while ( x <= 10 ) { total += x; x++; } 4. int x, total = 1; while ( x <= 100 ) { total += x; x++; } 5. int y = 1; while ( y > 0 ) { cout << y << endl; y--; }

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

View Full Document
4.12 Program Output: 1 4 9 16 25 36 49 64 81 100 Total is 385
University of Cincinnati Department of Computer Science CS 121-002 Computer Science 1 Homework Problem #17 Benjamin D. Jones 22 January 2008 1. Introduction The purpose of this laboratory assignment is to understand the application of while loops in a simple real world problem, involving (possibly large) sequences of data. The program determines the winner of a sales contest inputs the number of units sold by each salesperson. The salesperson who sells the most units wins the contest. The program uses a while statement to determine and print the largest number of 10 numbers input by the user. 2. The Program // *********************************************************************** // File: largestnum.cpp // // Find the largest number - User inputs ten integers, and the program // outputs the largest of the set. // // Author: Benjamin Jones // Created: 22 January 2008 // Updated: Original // // Assignment: 2.16 // Compiler: MinGW32 G++ 3.4.2 (GNU) //

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

View Full Document
// Inputs: Ten arbitrary integers. // Outputs: Display message "The largest number was: <largestNumber>" // ********************************************************************* // // Design: // // 1. Get input from user // a. While the user has not yet entered ten integers // 1. Read the next input // 2. Validate that input is positive // a. If not, continue the loop. // // 2. Decide if current integer is the largest of all the entered inputs // a. If so, then set the current integer to be the largest integer // b. Increment the counter and continue the loop // // 3. Display message "The latgest number was: <largestNumber>" // // ********************************************************************** #include <iostream> using namespace std; const int OK = 0; int main() { // Declare and initialize counter, currentNumber, and largestNumber
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 15

homework2 - 4.11 1 if age >= 65 cout <"Age is greater than...

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

View Full Document
Ask a homework question - tutors are online