homework2 - 4.11 1. if ( age >= 65 ) cout < "Age...

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

View Full Document Right Arrow Icon
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--; }
Background image of page 1

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

View Full DocumentRight Arrow Icon
4.12 Program Output: 1 4 9 16 25 36 49 64 81 100 Total is 385
Background image of page 2
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) //
Background image of page 3

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

View Full DocumentRight Arrow Icon
// 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
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 15

homework2 - 4.11 1. if ( age &gt;= 65 ) cout &lt; &quot;Age...

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

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