09-16-09 - Termination The program will end after the user...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
Iteration, Repetition, Indefinite While Loop Description This simple program askes for 2 numbers from the user and computes the sum of those numbers. It repeats this activity (loops) as many times as the user wants to. It illustrates these new concepts: 1. while loops (indefinite loops) 2. using an input data item as a signal to end looping 3. named constants 4. boolean variables Input User will supply 2 numbers, one at a time when prompted. Output The program will print to the screen the sum of the two numbers multiplied by 5.
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Termination The program will end after the user gives a pair of numbers where the first is 0. Notes Test for equality Note that in the "if" statement, we compare the value of the variable "first" to 0. We are testing it for equality, and the boolean operator for equals is "==". A common error is to use "=" to compare for equality, but "=" is the assignment operator and if you use that in a boolean expression your program will give erroneous results....
View Full Document

This note was uploaded on 11/30/2009 for the course COMP 110 taught by Professor Stotts during the Spring '08 term at UNC.

Ask a homework question - tutors are online