August 2002
Beginner
1122 pages
22h 1m
English
The while statement is another way of affecting the order of program execution. This conditional statement executes the statement under its control as long as a certain condition is true. Such potentially repeated execution is called a loop; a loop controlled by a while statement is called, logically enough, a while loop. Figure 3.23 is a program that uses a while loop to challenge the user to guess a secret number from 0 to 9, and keeps asking for guesses until the correct answer is entered.
#include <iostream> using namespace std; int main() { short Secret; short Guess; Secret = 3; cout << "Try to guess my number. Hint: It's from 0 to 9" << endl; cin >> Guess; while (Guess ... |
Read now
Unlock full access