Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Creating a Hi-Lo game in BASIC

codestar4codestar4 Posts: 1Member
Hello Everyone,

Well, I'm teaching myself to program in BASIC via online tutorials. I've read one tutorial on making a Hi-Lo game. Once I had created the game in the tutorial I started editing it, and adding some features.

This is the original version. (In which was still incorrect and I had to fix some typos to get it to work.)
[code]
// The Hi-Lo Game, by [[Insert Your Name Here!]]
2
// Start of each round of the game
clear screen
print "I am thinking of a number between one and ten."

print "Take a guess and I will tell you if it is higher or lower."
// Ask the user what he thinks the answer is with input and put in variable a.
input a
// See if what the user said is right.
if a>5 then
print "Sorry, the number is lower. Press enter to try again."
end if
if aprint "Sorry, the number is higher. Press enter to try again."
end if
if a=5 then print "You got it dude!"
end
end if
// Press enter to continue
input b
//Return to start of the round.
goto 2[/code]

In this version you get to repeatedly guess until you are correct.(After you fix the typos.)

In my version you get three tries, then the game ends unless on one of those three tries, you guess the correct answer. The range is 1-10. Here is my version:
[code]
clear screen
print "The Hi-Lo Game"

print "By: Cody Morgan"

print "I am thinking of a number between one and ten."


print "Take a guess and I will tell you if it is higher or lower."


print "You have three tries, if you do not guess the correct answer, you lose."
// Ask the user what he thinks the answer is with input and put in variable a.
input a
// See if what the user said is right.
if a>9 then
print "Sorry, the number is lower. You have two more tries. Good luck."
input b
end if
if a<9 then
print "Sorry, the number is higher. You have two more tries. Good luck."
input b
end if
if a=9 then print "You got it dude!"
end
end if
// Press enter to continue
if b>9 then
print "Sorry, the number is lower. You have one more try. Good luck."
input c
end if
if b<9 then
print "Sorry, the number is higher. You have one more try. Good luck."
input c
end if
if b=9 then
print "You got it dude!"
end
end if
if c>9 then
print "Sorry, the number is lower. You lose."
end
end if
if c<9
print "Sorry, the number is higher. You lose."
end
if c=9
print "You got it dude!"
end
[/code]

I'm using Notepad to edit the code and YABasic to execute it. ( I do not know if this matters or not. )

My problem is, the number in that case is always 9 (unless I change it). I want it to generate a random number when executed that way it can change 9 to any number 1-10.

If your an engineer, here are your design constraints:
Answer must be generated randomly.
Answer must be controlled within a certain range(such as 1 to 10)
Answer must stay constant throughout an entire game.(meaning the number won't change between guesses.

Please post the code that generates random number and explain why/how each variable/integer works, and why/how it generates a random number. Then please post your code in my code the way it should be laid out. Please explain thoroughly!

--Thanks in advance,
Cody

Sign In or Register to comment.