Author |
Message |
theanimator
|
Posted: Thu Feb 16, 2006 10:49 am Post subject: Qbasic help please! |
|
|
I was wondering if anyone could help me with Qbasic? if so, i need help with this code: code: | CLS
PRINT "how many stars do you want";
INPUT star
FOR i = 1 TO star
LET star = star + 1
PRINT "*";
PRINT
NEXT i
|
basically when I run it, the program is supposed to look like this
run: code: | how many stars do you want? input
*
**
***
****
*****
etc. depending on how many stars are inputed |
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
codemage
|
Posted: Thu Feb 16, 2006 1:44 pm Post subject: (No subject) |
|
|
You can do that with two for loops.
In Turing, it would look like:
code: |
for dummy1 : 1 .. number
for dummy2 : 1 .. dummy1
put "*" ..
end for
put ""
end for
|
|
|
|
|
|
|
theanimator
|
Posted: Thu Feb 16, 2006 5:14 pm Post subject: (No subject) |
|
|
ok, but i need it for Qbasic. So, for two loops, how? i've tried but can't figure it out. |
|
|
|
|
|
[Gandalf]
|
Posted: Thu Feb 16, 2006 5:48 pm Post subject: (No subject) |
|
|
Oh! BASIC! Let's see what I remembers...
Ok, normally I shouldn't give you the answer, but this will be an exception since it is a fairly simple program. See what I am doing and learn from it. So here it is:
BASIC: | INPUT "How many stars do you want to display? "; starAmount
FOR index = 1 TO starAmount
FOR starsToPrint = 1 TO index
PRINT "*";
NEXT starsToPrint
PRINT " "
NEXT index |
Note that you can have the INPUT statement on just one line. |
|
|
|
|
|
theanimator
|
Posted: Fri Feb 17, 2006 8:13 am Post subject: (No subject) |
|
|
thank you for the help. I just don't understand the nested loops so much. I am starting to understand them more tho. I might be back again for help. Thanks again. |
|
|
|
|
|
|