I Am Way Confused


Recommended Posts

Alright, so i have this assignment for a class, and i have what i hope to be most of it done, but i just cant seem to figure out how to do a certain part of it.

the assignment calls for making a program where a random number is generated and the user gets a chance to input a guess. the program will then print out if the guess is lower or higher or the same as the random number. and if it isent the same, it alows them to continue to guess untill they get it right.

so far i have been able to get the random number generated and for it to tell you if your guess is higher lower or the same. but i cant figure out how to get it to allow the user to continue to guess without re-starting the program and thus getting a compleatly different random number.

here is my code so far.

DIM guess AS SINGLE

DIM higer AS STRING

DIM lower AS STRING

RANDOMIZE TIMER

INPUT "Please enter in your guess: ", guess

secretnum = INT(1000 * RND + 1)

IF guess > secretnum THEN

PRINT "Lower"

IF guess < secretnum THEN

PRINT "Higher"

IF guess = secretnum THEN

PRINT "You got it!"

END IF

END IF

END IF

i am pretty sure i have to put in a DO WHILE or DO UNTIL loop. but whenever i try to put one in it gives me either an error saying that its a loop or do without the other. and if it dosent give me that error message, then it just allows me to enter my first guess and nothing else. dosent even print out if its higher lower or if i guess it correctly.

please, im not asking for anyone to do this for me, but i have been trying to figure this out for hours, and im about to burn out. i just need someone to either tell me how to make it loop, or at least send me in the right direction.

thanks.

alright, so i just got a loop to work with it, but now after i enter in the first value, it either just continues to let me enter in guesses without telling me if its higher or lower. or it keeps sayin lower until once again, it just stops telling me. why is that happening?

here is my updated code.

CLS

DIM secretnum AS SINGLE

DIM guess AS SINGLE

DIM higer AS STRING

DIM lower AS STRING

RANDOMIZE TIMER

secretnum = INT(1000 * RND + 1)

WHILE secretnum <> guess

INPUT "Please enter in your guess: ", guess

IF guess > secretnum THEN

PRINT "Lower"

IF guess < secretnum THEN

PRINT "Higher"

IF guess = secretnum THEN

PRINT "You got it!"

END IF

END IF

END IF

wend

once again, any help is VERY appriciated.

Edited by confusedguy
Link to post
Share on other sites
Alright, so i have this assignment for a class, and i have what i hope to be most of it done, but i just cant seem to figure out how to do a certain part of it.

the assignment calls for making a program where a random number is generated and the user gets a chance to input a guess. the program will then print out if the guess is lower or higher or the same as the random number. and if it isent the same, it alows them to continue to guess untill they get it right.

so far i have been able to get the random number generated and for it to tell you if your guess is higher lower or the same. but i cant figure out how to get it to allow the user to continue to guess without re-starting the program and thus getting a compleatly different random number.

here is my code so far.

DIM guess AS SINGLE

DIM higer AS STRING

DIM lower AS STRING

RANDOMIZE TIMER

INPUT "Please enter in your guess: ", guess

secretnum = INT(1000 * RND + 1)

IF guess > secretnum THEN

PRINT "Lower"

IF guess < secretnum THEN

PRINT "Higher"

IF guess = secretnum THEN

PRINT "You got it!"

END IF

END IF

END IF

i am pretty sure i have to put in a DO WHILE or DO UNTIL loop. but whenever i try to put one in it gives me either an error saying that its a loop or do without the other. and if it dosent give me that error message, then it just allows me to enter my first guess and nothing else. dosent even print out if its higher lower or if i guess it correctly.

please, im not asking for anyone to do this for me, but i have been trying to figure this out for hours, and im about to burn out. i just need someone to either tell me how to make it loop, or at least send me in the right direction.

thanks.

alright, so i just got a loop to work with it, but now after i enter in the first value, it either just continues to let me enter in guesses without telling me if its higher or lower. or it keeps sayin lower until once again, it just stops telling me. why is that happening?

here is my updated code.

CLS

DIM secretnum AS SINGLE

DIM guess AS SINGLE

DIM higer AS STRING

DIM lower AS STRING

RANDOMIZE TIMER

secretnum = INT(1000 * RND + 1)

WHILE secretnum <> guess

INPUT "Please enter in your guess: ", guess

IF guess > secretnum THEN

PRINT "Lower"

IF guess < secretnum THEN

PRINT "Higher"

IF guess = secretnum THEN

PRINT "You got it!"

END IF

END IF

END IF

wend

once again, any help is VERY appriciated.

... What's a higer ?

Link to post
Share on other sites
Alright, so i have this assignment for a class, and i have what i hope to be most of it done, but i just cant seem to figure out how to do a certain part of it.

the assignment calls for making a program where a random number is generated and the user gets a chance to input a guess. the program will then print out if the guess is lower or higher or the same as the random number. and if it isent the same, it alows them to continue to guess untill they get it right.

so far i have been able to get the random number generated and for it to tell you if your guess is higher lower or the same. but i cant figure out how to get it to allow the user to continue to guess without re-starting the program and thus getting a compleatly different random number.

here is my code so far.

DIM guess AS SINGLE

DIM higer AS STRING

DIM lower AS STRING

RANDOMIZE TIMER

INPUT "Please enter in your guess: ", guess

secretnum = INT(1000 * RND + 1)

IF guess > secretnum THEN

PRINT "Lower"

IF guess < secretnum THEN

PRINT "Higher"

IF guess = secretnum THEN

PRINT "You got it!"

END IF

END IF

END IF

i am pretty sure i have to put in a DO WHILE or DO UNTIL loop. but whenever i try to put one in it gives me either an error saying that its a loop or do without the other. and if it dosent give me that error message, then it just allows me to enter my first guess and nothing else. dosent even print out if its higher lower or if i guess it correctly.

please, im not asking for anyone to do this for me, but i have been trying to figure this out for hours, and im about to burn out. i just need someone to either tell me how to make it loop, or at least send me in the right direction.

thanks.

alright, so i just got a loop to work with it, but now after i enter in the first value, it either just continues to let me enter in guesses without telling me if its higher or lower. or it keeps sayin lower until once again, it just stops telling me. why is that happening?

here is my updated code.

CLS

DIM secretnum AS SINGLE

DIM guess AS SINGLE

DIM higer AS STRING

DIM lower AS STRING

RANDOMIZE TIMER

secretnum = INT(1000 * RND + 1)

WHILE secretnum <> guess

INPUT "Please enter in your guess: ", guess

IF guess > secretnum THEN

PRINT "Lower"

IF guess < secretnum THEN

PRINT "Higher"

IF guess = secretnum THEN

PRINT "You got it!"

END IF

END IF

END IF

wend

once again, any help is VERY appriciated.

... What's a higer ?

its simply a typo. its ment to say higher

Link to post
Share on other sites

I had some code, but after looking at it it does not work. I may give it a another shot.

I did notice something. You only need to use the DIM statement with variables

these two lines, I don't think are needed

DIM higer AS STRING

DIM lower AS STRING

Edited by shanenin
Link to post
Share on other sites

CLS

DIM guess AS SINGLE

RANDOMIZE TIMER
secretnum = INT(1000 * RND + 1)

DO
INPUT "Please enter your guess ", guess
IF guess > secretnum THEN
PRINT "Lower"
END IF
IF guess < secretnum THEN
PRINT "Higher"
END IF
IF guess = secretnum THEN
PRINT "You got it!"
EXIT DO
END IF
LOOP

Hmm....

Classic Basic:

10 DIM guess AS SINGLE
20 RANDOMIZE TIMER
30 secretnum = INT(1000 * RND + 1)
40 INPUT "Please enter your guess ", guess
50 IF guess = secretnum THEN GOTO 90
60 IF guess > secretnum THEN PRINT "Lower"
70 IF guess < secretnum THEN PRINT "Higher"
80 GOTO 40
90 PRINT "You got it!"

Visual Basic.NET:

Module Hello
Sub Main()
Dim rnd As New Random
Dim secretNum As Integer = rnd.Next(1000)
Dim guess As Integer
Dim done As Boolean = False

Do Until done
Console.Write("Please enter your guess ")
guess = Val(Console.ReadLine)
Console.WriteLine(guess)
If guess > secretNum Then
Console.WriteLine("Lower")
ElseIf guess < secretNum Then
Console.WriteLine("Higher")
Else
Console.WriteLine("You got it!")
done = True
End If
Loop

End Sub
End Module

Observation: the usability of a Basic dialect is inversely proportional to its sophistication. Unstructured (classic) Basic is more usable than structured Basic (QB), structured Basic is more usable than object-oriented Basic (VB.NET). The VB.NET program is twice the size of the unstructured program, took ten times as long to write, and looks like mush. The QB program is in between.

Edited by jcl
Link to post
Share on other sites

Very nice.

I finally found a freeware QBasic proggy at http://www.winsite.com/bin/Info?2000000035557 and jcl's first prog works fine.

I also have a freeware proggy called Just Basic v. 1.0 that I picked up somewhere that had this exercise as a tutorial program:

 ' Here is an interactive HI-LO
' Program

[start]
guessMe = int(rnd(1)*1000) + 1

' Clear the screen and print the title and instructions
cls
print "HI-LO"

print

print "I have decided on a number between one"
print "and a thousand, and I want you to guess"
print "what it is. I will tell you to guess"

print "higher or lower, and we'll count up"
print "the number of guesses you use."

print

[ask]
' Ask the user to guess the number and tally the guess
input "OK. What is your guess?"; guess

' Now add one to the count variable to count the guesses
let count = count + 1

' check to see if the guess is right
if guess = guessMe then goto [win]
' check to see if the guess is too low
if guess < guessMe then print "Guess higher."

' check to see if the guess is too high
if guess > guessMe then print "Guess lower."

' go back and ask again
goto [ask]

[win]
' beep once and tell how many guesses it took to win
beep
print "You win! It took "; count; " guesses."

' reset the count variable to zero for the next game
let count = 0

' ask to play again
input "Play again (Y/N)"; play$
if instr("YESyes", play$) > 0 then goto [start]

print "Press ALT-F4 to close this window."

end

It's interesting to see the differences between the various types of BASIC that have evolved.

Edited by bobbynichols
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...