Author 
Message 
junkpro11

Posted: Tue May 04, 2004 4:17 pm Post subject: christmas tree problem 


lol does anyone know how to make a christmas tree like this?
*
***
*****
*******
ignore the dashes....
thanks






Sponsor Sponsor



Cervantes

Posted: Tue May 04, 2004 4:21 pm Post subject: (No subject) 


ya, read up on the "put" command.
here's what the code will look like:
code: 
put " *"
put " ***"
put " *****"
put "*******"







junkpro11

Posted: Tue May 04, 2004 4:25 pm Post subject: (No subject) 


sorri i wasnt clear
i dont want to just use "put"
i want to get a number, eg like 5 and make a christmas tree like this:
*
***
*****
again ignore the dashes






Cervantes

Posted: Tue May 04, 2004 4:39 pm Post subject: (No subject) 


oh, okay thats a pretty good question actually. simplest way is to use repeat and a for loop and play around with it until you get it
heres what i came up with
code: 
var base : int
put "Enter base width : " ..
get base
for t : 1 .. base
put repeat (" ", base  t) ..
put repeat ("*", t * 2  1)
end for







junkpro11

Posted: Tue May 04, 2004 4:48 pm Post subject: (No subject) 


thanks for ur help!!!!!!
i need to make a circle now with the asterisks...i think the closest thing i can make is an octagon though......so can i use repeat for making a "circle"?






Cervantes

Posted: Tue May 04, 2004 5:24 pm Post subject: (No subject) 


interesting problem.
heres what i came up with:
code: 
var radius : int
put "enter radius : " ..
get radius
var x, y : real
x := radius  1
for c : 1 .. radius * 2 + 1
x += 1
y := sqrt (radius ** 2  x ** 2)
locate (round (x) + maxrow div 2, round (y) + maxcol div 2)
put "*"
locate (round (x) + maxrow div 2, round (y) + maxcol div 2)
put "*"
end for

unfortunately in text the width of a character is less than its height, so it looks very, very off. also it looks off because locate requires rounding.






Paul

Posted: Tue May 04, 2004 5:51 pm Post subject: (No subject) 


Hey, if u enter 5, it looks like a rupee in Zelda!






junkpro11

Posted: Tue May 04, 2004 7:32 pm Post subject: (No subject) 


um....sorri if this sounds dumb.....but can u explain the code u did cuz i am new at this and i duno wat that code meant....






Cervantes

Posted: Tue May 04, 2004 7:40 pm Post subject: (No subject) 


i don't really know what it means either I basically played around altering and fixing stuff until i came up with that.
but basically, i used the equation of a circle. thats x^2 + y^2 = r^2. rearange that so that we get y^2 = r^2  x^2, then sqrt it all so we get y = sqrt (r^2  x^2). so now we've got x and y values (got x because we are just increasing x every time). so now locate at (x,y) and draw a *. I've got 2 locates and 2 puts. look what happens when you take one of them out. and as for the for loop being 1 .. radius * 2 + 1, look what happens when you take off the + 1. look what happens when you take off the *2.
this is how i program try something, fix it, try more, fix more, until i get it to work. Then i know how to do it, and if i have the energy i rewrite the code nice and organized and add any features i want.






junkpro11

Posted: Tue May 04, 2004 8:11 pm Post subject: (No subject) 


wow.....well im a slow processor so i'll think about it for a while....thanks alot for the help!






