Click here to Skip to main content
15,880,972 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm currently a senior in HS learning QB64... in school. I've only been programming for a several weeks and absolutely love it. Sucks I waited till senior year to take a programming class. Anyway here is my code. It is supposed to input three numbers and then output the largest number in circles placed in random spots with random size.

SCREEN _NEWIMAGE(1000, 500, 256)
DIM num1 AS INTEGER
DIM num2 AS INTEGER
DIM num3 AS INTEGER

CLS

RANDOMIZE TIMER

PRINT "INPUT NUMBERS BETWEEN 1 and 5."
PRINT
SLEEP 3
PRINT
INPUT "ENTER FIRST NUMBER: ", num1
INPUT "ENTER SECOND NUMBER: ", num2
INPUT "ENTER THIRD NUMBER: ", num3

IF num1 > num2 AND num3 THEN
FOR r = 1 TO num1
CIRCLE (RND * 999, RND * 499), (RND * 100) + 10
NEXT r
ELSE IF num2 > num1 AND num3 THEN
FOR x = 1 TO num2
CIRCLE (RND * 999, RND * 499), (RND * 100) + 10
NEXT x
ELSE
FOR w = 1 TO num3
CIRCLE (RND * 999, RND * 499), (RND * 100) + 10
NEXT w
END IF
END IF
END


ANYWAY THE FIRST 2 IFS WORK BUT IF THE USER INPUTS THE HIGHEST NUMBER FOR THE THIRD NUMBER IT WILL NOT OUTPUT THAT AMOUNT OF CIRCLES.

What I have tried:

Everything I can think of. It makes no sense to me how it is not working.
Posted
Updated 24-Sep-16 6:12am

Look at your IF:
VB
IF num1 > num2 AND num3 THEN
That doesn't do what you think it does!
You think it means "if number one is the greatest of the three numbers" - it doesn't. The AND breaks it into two separate conditions and insists that both must be true: So "if number one is greater than number two" AND "number three all on it's own".
Try this:
VB
IF num1 > num2 AND num1 > num3 THEN

But why the heck are you learning QBasic in 2016? It's pretty much a dead language, and not something anyone should be trying to learn coding from! It hasn't been distributed since Windows 2000! :laugh:
Look at VB (or better C#) and a (free) copy of Visual Studio Community Edition - it'll make your life a lot, lot easier!
 
Share this answer
 
v2
Try to replace
VB
IF num1 > num2 AND num3 THEN

with
VB
IF num1 > num2 AND num1 > num3 THEN
 
Share this answer
 
IF Solutions are ok.

Bashing BASIC without knowing about QB64 is not ok.

QB64 is a modern extended version of the Basic programming language that retains QB4.5/Qbasic compatibility and compiles natively for Windows, Linux and macOS.

www.qb64.org
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900