Computer Science Canada

making a hollow asterisks box

Author:  junkpro11 [ Sun Apr 25, 2004 8:34 pm ]
Post subject:  making a hollow asterisks box

im a noob at turing...im prob the worst in class cuz logic isnt my stong suit.and i took programming to learn sth different. can anyone help me how to make a hollow asterisk box with number of stars across input
eg. the input is 4
the box would be
****
* *
* *
* *
****

my code doesnt work....it onli makes this
****
**
**
****
code:

var inum : int
put "enter number"
get inum
for row : 1 .. inum
    for column : 1 .. inum
        if column = 1 or column = inum or row = 1 or row = inum then
            put "*" ..
        end if
    end for
    put ""
end for

Author:  junkpro11 [ Sun Apr 25, 2004 8:36 pm ]
Post subject: 

what the? the boz is supposed to be outlined by asterisks but the inside is supposed to hollow

dunno y the msg appeared funni Embarassed

Author:  Delos [ Mon Apr 26, 2004 9:49 am ]
Post subject: 

Hey, this is easy actually!

Just add an 'else' statement to your if condition.

code:

else
put " "..


It look funny on the board due to some odd space removal thing used...

Author:  Flashkicks [ Mon Apr 26, 2004 10:34 am ]
Post subject: 

I remember having to do this when i was in grade nine! Laughing Rolling Eyes We also had to make a Christmas tree which most the kids had problems with..lol And its funny- i was one of them as well Embarassed Rolling Eyes Laughing

Author:  Raugrist [ Mon Apr 26, 2004 11:19 am ]
Post subject: 

Even easier like this:
code:

var num : int
get num
put repeat ("*", num)
put "*", repeat (" ", num - 2), "*"
put "*", repeat (" ", num - 2), "*"
put "*", repeat (" ", num - 2), "*"
put repeat ("*", num)

Good ol' repeat function.

Author:  junkpro11 [ Mon Apr 26, 2004 8:49 pm ]
Post subject: 

thank you everyone! im in gr. 10 but teacher didnt teach us repeat yet... Embarassed

this question is on the hw sheet...to prepare us for the test on wed. u can see im not tat good with programming....lacking logic so ty for helping me!!!!



: