Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Qbasic help please!
Index -> Programming, Visual Basic and Other Basics -> Other Basics
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
theanimator




PostPosted: 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
Sponsor
sponsor
codemage




PostPosted: 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




PostPosted: 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]




PostPosted: 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




PostPosted: 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.
Display posts from previous:   
   Index -> Programming, Visual Basic and Other Basics -> Other Basics
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: