Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   Other Programming (https://www.askmehelpdesk.com/forumdisplay.php?f=437)
-   -   Stuck on computing homework ! (https://www.askmehelpdesk.com/showthread.php?t=398038)

  • Sep 20, 2009, 07:30 AM
    natalie1xxx
    stuck on computing homework !
    Stuck on computing homework ? Help please!!
    okay well the question is " write two nested loops to print a pattern if stars on 12 lines of the screen. there should be one star on the first line, two stars on the second line, ... and so on until there are 12 stars on the 12th line. "

    there is also a little diagram of what it should look like .

    *
    **
    ***
    ****
    *****
    ******
    *******
    ********
    *********
    **********
    ***********
    ************

    we use truebasics :) and I have tried to complete this task but its hard and I can't do it , here's what I've got so far.

    FOR down = 1 to 12
    LET across =0

    DO
    LET across = across +1

    PRINT "*";

    LOOP until across = down

    DO WHILE across <12
    PRINT "*";
    LET across = across +12
    LOOP
    PRINT
    NEXT down
    END


    which is probably ALL wrong but help please! Someone must be an expert at programming :) thanks xxxx
  • Sep 21, 2009, 09:09 AM
    Perito

    I think all you need is this loop:

    Let LengthOfString = 0
    For I = 1 To 12
    Let LengthOfString = LengthOfString + 1
    For j = 1 To LengthOfString
    Print "*"; ' This will print a star for as many as LengthOfString permits it to.
    Next j
    Print ' this will create a new line.
    Next I

    At the start of the inner loop, you increment a counter that determines how many stars to print.
    The inner loop ("j" is the index) prints a single character. You seen to know what the ';' is for.
    After the inner loop is finished. You need a newline to start printing on.

  • All times are GMT -7. The time now is 02:22 PM.