• entries
31
97
• views
13508

# today was a little different

314 views

I got up at f**king 3:58 p.m this afternoon and im still tired [smile] i went over to my friends house and he wasn't there:( im almost halfway through my book im waiting on my dinner so i made this program
#include#include#includeusing namespace std;int main(){    int num = ((rand() % 100) + 1);   //make a random number between 1 and 100    int tries = 0;    int guess;        do        {                cout<<"enter a number between 1 and 100";                cin>> guess;                tries++;                                if(guess > num)                    cout<<"thats too high\n\n";                if(guess < num)                    cout<<"thats too low\n\n";        }while(guess != num);    cout<<"you got it in"<}

and i hope my show comes on tonight.

you forgot to seed the random number generator
srand(time(0));


in case you've noticed that you're guessing the same number every time, this is why

. . .and put an "else" before that second if() statement. Since the second if() is irrelevent if the first succeeds, it should rightly be ignored if that's the case. Hence adding an "else" before the second if() will increase the speed of your program greatly.

Oh, and it should never take you more than seven guesses to get the right number.

thanks i didn't even notice that.

## Create an account

Register a new account