Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
christmas tree problem
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

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!
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 1  [ 10 Posts ]
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: