#include <iostream>#include <cstdlib>#include <ctime>using namespace std;int main(){// Why a blank line? srand(time(0)); int number; int guess=rand()%100+1; // When you start guessing, the guess is set automatically. No need to set it here. See (A). cout<<"\t\tGUESS MY NUMBER\n\n"; cout<<"enter a number between 1 and 100 for the computer to guess: \n"; cin>>number; while (number>100 || number<0) { cout<<"Enter a number between 1 and 100: "; cin>>number; } while(guess!=number) // Why another indentation? { guess=rand()%100+1; // (A) cout<<"Is it: " <<guess <<"\?\n"; } if (guess==number) // When you end your while loop, guess is always equal to number. No need to check it another time. { cout<<"your number was " <<number; }}
Emiel