My Newb Program Error...

Started by
11 comments, last by Ezbez 14 years, 4 months ago
Looks very good. Now, some cleaning up. Comments are points of interest.

#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
Advertisement
Quote:Original post by soitsthateasy
Thanks everyone!!! finally got it: code below:

*** Source Snippet Removed ***


you can set the guess 0, you shoulde check for guess < 1 instead of 0. and it will enter an infinite loop ^^
taytay
Just saying congrats, and that I that I agree with emiel1's and shultays's comments!

This topic is closed to new replies.

Advertisement