Guess a number using "while" loop - C++ Statement

C++ examples for Statement:while

Description

Guess a number using "while" loop

Demo Code

#include <iostream>
using namespace std;
int main() {//w w  w .  ja v  a 2  s  .c o m
   int secret = 15;
   int guess = 0;
   // "!=" is the "not-equal" conditional:
   while(guess != secret) { // Compound statement
      cout << "guess the number: ";
   cin >> guess;
}
cout << "You guessed it!" << endl;
}

Result


Related Tutorials