Sunday, July 12, 2009

Write a C program that plays the game "guess the number" as follows: Your program chooses the number

to be guessed be selecting an integer at random in the range 1 to 1000.





The program then types:





===================================


I have a number between 1 an 1000.


Can you guess my number?


Please type your first guess.


===================================





The player then types a first guess. The program responds with one of the following:





===================================


1. Excellent! You guessed the number!


Would you like to play again (y or n)?


2. Too low. Try again.


3. Too high. Try again.

Write a C program that plays the game "guess the number" as follows: Your program chooses the number
Hopefully you understand BASIC:


SeedRnd MilliSecs()


Print("============================......


Print("I have a number between 1 an 1000.")


Print("Can you guess my number?")


Print("Please type your first guess")


Print("============================......


number=Rnd(1,1000)


answer=False


.begin


Repeat


guess$=Input("")


If guess$%26gt;number Then


Print("Too high, guess again")


Else


If guess$%26lt;number Then


Print("Too low, guess again")


Else


If guess$=number Then


answer=True


EndIf


EndIf


EndIf


Until answer=True


correct$=Input("Excellent! You guessed the number! Play again(1=Yes,2=No)")


If correct$=1 Then


Gosub begin


Else


If correct$%26lt;%26gt;1 Then


End


EndIf


EndIf


I hope this helps (sorry indenting didn't come through).EDIT


changed .begin spot to behind repeat.
Reply:Note: put the 'begin' loop before the number=Rnd(1,1000)


thing for it to work correctly. Report It



No comments:

Post a Comment