I'm writing a guessing game in QBasic , which kind of tells you that im not to this, and every time I run the code the rndnum is always 0. what should i change?
Asked
Active
Viewed 657 times
0
-
1Show us the complete code, otherwise we cannot help you. Also, qbasic is getting a bit old, there are many alternatives these days for beginners. I would suggest looking into Python or any other more modern language, you will find much more help online. – Bas Swinckels Feb 28 '15 at 15:23
-
1Show us some code. Have you initialized the random generator? What does RND return? – usr1234567 Feb 28 '15 at 15:23
-
http://brisray.com/qbasic/qchance.htm – nkcode May 07 '15 at 20:33
-
Some Basic dialects require a parameter such as RND(1) – eoredson Aug 28 '16 at 01:25
2 Answers
0
If you are saying that the very first returned number is zero every time the program is run then all you need is to add the randomize statement as a one-time called procedure. If you are instead saying that as you are iterating through the same code in a loop it is returning zero every time then there is something else wrong - most likely that for whatever reason QBasic does not recognize RND as a function and therefore assumes it's a variable, which would by default be set to zero. The correct syntax would be something like:
Lowerbound = 1
Upperbound = 100
RANDOMIZE
FOR X = 1 TO 10
PRINT INT((Upperbound - Lowerbound + 1) * RND + Lowerbound)
NEXT X

josliber
- 43,891
- 12
- 98
- 133

Bill Hileman
- 91
- 7