I think you have to initialise the seed with current time to get different random numbers every execution.
On Sun, Feb 22, 2009 at 12:43 PM, Reepak <[email protected]>wrote: > the following is number guessing game the randomize function is > always choosing 41 as the guessing number. Please help > > #include<iostream.h> > #include<time.h> > #include<stdlib.h> > #include<conio.h> > > int main(void) > { > int score,leftchances,number,guessnumber; > leftchances=6; > score=0; > randomize(); > number=int (rand()%100); > char input; > clrscr(); > start: > cout<<"\n Welcome To Number Guessing Game"; > cout<<"\n Computer Will Select Number In Between 0 To 100"; > cout<<"\n You Will Be Given Six Chances To Guess That Number\n"; > > do > { > cout<<"\n"<<leftchances<<":Guses Remaining\n"; > cin>>guessnumber; > if(guessnumber>100||guessnumber<0) > { > cout<<"\n Your Guess Should Be In Between 0 To > 100 Numbers Only"; > leftchances--; > } > if(guessnumber>number) > { > cout<<"\n Your Guess Is HIGH"; > leftchances--; > } > > if(guessnumber<number) > { > cout<<"\n Your Guess Is LOW"; > leftchances--; > } > > if(guessnumber==number) > { > cout<<"\n CONGRATULATIONS YOUR GUESS IS > CORRECT"; > cout<<"\n the number was"<<number; > score=leftchances*10; > cout<<"\n Your Score Is "<<score; > break;}} > > while((guessnumber!=number)&&(leftchances!=0) > if (leftchances==0) > { > cout<<"\n Sorry You Could Not Guess"; > cout<<"\n The Number Was"<<number; > score=leftchances*10; > cout<<"\n Your Score Is"<<score; > cout<<"\n Remaining Guesses"<<leftchances;} > cout<<"Want To Play Again Press Y"; > cin>>input; > if(input==Y||input==y) > {goto start;} > system ("pause"); } > > > > [Non-text portions of this message have been removed]
