the assignment is......
1. Write a program that repeats 20 times.
Use a FOR-NEXT loop that counts
from 1 to 20.
2. Inside the loop, assign random numbers to two variables with the RND function.
The example above shows one random number being chosen
(LET newnumber=RND). Since you
need two random numbers, you will need
two different variables.
3. Now perform simple math with the two random numbers. Add the two random numbers, subtract the two random numbers, multiply the two random numbers, and divide the two
random numbers. Store the answer for
each calculation in a separate variable (something like answer1, answer2, etc.).
4. Inside the loop, use a PRINT USING statement to print your answers in
six columns ( the two random numbers and the results
of the addition, the subtraction, the multiplication, and the division operations.)
I can't get the title "num1" and "num2" to print above 20 randomized numbers... i can get the 20 numbers to randomize only if i dont print the title
somebody help i need help==D!!!
just learning qbasic! got into a snag.
- burger2227
- Veteran
- Posts: 2467
- Joined: Mon Aug 21, 2006 12:40 am
- Location: Pittsburgh, PA
OPTION 1: Post your code! We will NOT write the homework program FOR YOU! We can help you when you show us what you are doing or not doing.
OPTION 2: Shoot your teacher for making you use LET, lol. It is NOT necessary! I HATE teachers that get students hooked on stupid stuff! Many also get hooked on GOTO as a cure-all. Loops are much better!
OPTION 3: Go cheat somewhere else!
Ted
OPTION 2: Shoot your teacher for making you use LET, lol. It is NOT necessary! I HATE teachers that get students hooked on stupid stuff! Many also get hooked on GOTO as a cure-all. Loops are much better!
OPTION 3: Go cheat somewhere else!
Ted
mm
well im not asking you to do the hw lol... just need to know how to get the title to print ONCE at top without screwing up the 20 randomized numbersburger2227 wrote:OPTION 1: Post your code! We will NOT write the homework program FOR YOU! We can help you when you show us what you are doing or not doing.
OPTION 2: Shoot your teacher for making you use LET, lol. It is NOT necessary! I HATE teachers that get students hooked on stupid stuff! Many also get hooked on GOTO as a cure-all. Loops are much better!
OPTION 3: Go cheat somewhere else!
Ted
but here is my code atm
REM 4.10
REM Sean Wilson
REM 3-9-09
'
CLS
REM INPUT
RANDOMIZE TIMER
REM PROCESSING
REM OUTPUT
'
PRINT "Num1"; SPC(5); "Num2"
FOR n = 1 TO 20 STEP 1
LET newNumber1 = RND
PRINT USING "#.###"; newNumber1
NEXT n
'
FOR m = 1 TO 20 STEP 1
LET newNumber2 = RND
PRINT USING " #.###"; newNumber2
NEXT m
END

- burger2227
- Veteran
- Posts: 2467
- Joined: Mon Aug 21, 2006 12:40 am
- Location: Pittsburgh, PA
Because the screen scrolls up! Most screen modes have 23 rows to print text. You can add a semicolon after a PRINT to use rows 24 and 25 without scrolling. The 2 FOR loops use 40 rows! A semicolon also stops the PRINT cursor instead of going to the next row. You used it in your header.
Just use ONE FOR loop. Each time you get a RND, it gives you a different value. So get both each loop. I'm not sure how large the numbers can be as presently they only range from 0 to .999999. You can create larger values by multiplying RND by a number. Let me know if you need larger numbers! NOT too large though! Multiplication needs more # ahead of the decimal point in your prints.
You can do all of the random variable values and calculations in the FOR loop EACH loop. Then you PRINT USING all of the values up to 20 rows. You can place text in a PRINT USING statement:
tmp$ = "Num1 = #.#### Num2 = #.#### 1 * 2 = ##.#####" etc.
PRINT USING tmp$; num1; num2; num1 * num2, .......etc.
Keep the tmp$ string less than 80 spaces or you can use your PRINT header instead.
Now you should have 20 printed lines with 6 columns.
Ted
Just use ONE FOR loop. Each time you get a RND, it gives you a different value. So get both each loop. I'm not sure how large the numbers can be as presently they only range from 0 to .999999. You can create larger values by multiplying RND by a number. Let me know if you need larger numbers! NOT too large though! Multiplication needs more # ahead of the decimal point in your prints.
You can do all of the random variable values and calculations in the FOR loop EACH loop. Then you PRINT USING all of the values up to 20 rows. You can place text in a PRINT USING statement:
tmp$ = "Num1 = #.#### Num2 = #.#### 1 * 2 = ##.#####" etc.
PRINT USING tmp$; num1; num2; num1 * num2, .......etc.
Keep the tmp$ string less than 80 spaces or you can use your PRINT header instead.
Now you should have 20 printed lines with 6 columns.
Ted
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0