473,881 Members | 1,647 Online

# Christmas trees

How can my response to this problem be better? The pot doesn't work
that well when you enter 25, 21, 17 and some others.

The problem:

CHRISTMAS TREES

The grade 5 class at the local primary school wants some Christmas
tree outlines to colour in for the break-up session. You have to
write a program which will ask for an odd number representing the size
of the tree, rejecting negative quantities and numbers greater than
sixty, and then draw a tree centrally placed on the printer page
similar to the one below.
*
* *
* *
* *
* *
* *
* *
Base Line--- ***************
*
*
*******
* *
* *
***

The base line of the tree will be made of as many asterisks (*) as the
number that was input, and lines above it will have each of the
outline asterisks move in one space, until the single * appears at the
top.

The pot in which the tree rests should be scaled to suit the tree
size.

Click on treetest
Jun 27 '08 #1
8 3430
Bert <al************ *****@gmail.com writes:
How can my response to this problem be better? The pot doesn't work
that well when you enter 25, 21, 17 and some others.

The problem:

CHRISTMAS TREES
Are you going to go through all 33 problem from the Australian
Computer Competition Junior Sample Questions? This is the first and
the three-move knight's reach is the last. Have these been assigned

--
Ben.
Jun 27 '08 #2
On Sat, 21 Jun 2008 17:13:34 -0700 (PDT), Bert
<al************ *****@gmail.com wrote:
>How can my response to this problem be better? The pot doesn't work
that well when you enter 25, 21, 17 and some others.
snip problem description

Better than what? You didn't show what your response looks like. If
you haven't created one yet, then any working response you create
would be better.
Remove del for email
Jun 27 '08 #3
Jun 27 '08 #4
On Jun 22, 10:32 am, Ben Bacarisse <ben.use...@bsb .me.ukwrote:
Bert <albert.xtheunk no...@gmail.com writes:
How can my response to this problem be better? The pot doesn't work
that well when you enter 25, 21, 17 and some others.
The problem:
CHRISTMAS TREES

Are you going to go through all 33 problem from the Australian
Computer Competition Junior Sample Questions? This is the first and
the three-move knight's reach is the last. Have these been assigned

--
Ben.
Why not? I'll be like the only one who'll maybe get one problem done
in the two hours in my school cos none of the electives ever focus on
programming.
I'm largely self-taught with 5 or 6 programming books in my shelf and
once in year asking one of my dad's friends for help or posting on
Google Groups. I have no tutor, see?
Jun 27 '08 #5
On Jun 22, 8:13 am, Bert <albert.xtheunk no...@gmail.com wrote:
How can my response to this problem be better? The pot doesn't work
that well when you enter 25, 21, 17 and some others.

The problem:

CHRISTMAS TREES

The grade 5 class at the local primary school wants some Christmas
tree outlines to colour in for the break-up session. You have to
write a program which will ask for an odd number representing the size
of the tree, rejecting negative quantities and numbers greater than
sixty, and then draw a tree centrally placed on the printer page
similar to the one below.
*
* *
* *
* *
* *
* *
* *
Base Line--- ***************
*
*
*******
* *
* *
***

The base line of the tree will be made of as many asterisks (*) as the
number that was input, and lines above it will have each of the
outline asterisks move in one space, until the single * appears at the
top.

The pot in which the tree rests should be scaled to suit the tree
size.

Click on treetest
Jun 27 '08 #6
On Jun 23, 6:30 pm, redraiment <redraim...@gma il.comwrote:
On Jun 22, 8:13 am, Bert <albert.xtheunk no...@gmail.com wrote:
How can my response to this problem be better? The pot doesn't work
that well when you enter 25, 21, 17 and some others.
The problem:
CHRISTMAS TREES
The grade 5 class at the local primary school wants some Christmas
tree outlines to colour in for the break-up session. You have to
write a program which will ask for an odd number representing the size
of the tree, rejecting negative quantities and numbers greater than
sixty, and then draw a tree centrally placed on the printer page
similar to the one below.
*
* *
* *
* *
* *
* *
* *
Base Line--- ***************
*
*
*******
* *
* *
***
The base line of the tree will be made of as many asterisks (*) as the
number that was input, and lines above it will have each of the
outline asterisks move in one space, until the single * appears at the
top.
The pot in which the tree rests should be scaled to suit the tree
size.
Click on treetest

I posted it a little later. Find my other posts in this thread.
Jun 27 '08 #7
Bert said:
On Jun 23, 6:30 pm, redraiment <redraim...@gma il.comwrote:
>On Jun 22, 8:13 am, Bert <albert.xtheunk no...@gmail.com wrote:
<snip>
>>
Click on treetest

I posted it a little later. Find my other posts in this thread.
I did. I don't see any source, though.

If you mean the Web URL you posted, forget it. Very few will bother to
follow that link, at least until they know you a bit better. If you want
Usenet people to check out your source, reduce it to the smallest possible
program that still demonstrates the problem you're suffering, and post it
in a Usenet article together with an explanation of the problem and any
data required for running it.

No, I'm not telling you what to do. I'm suggesting a course of action that
will probably work for you. Obviously you do what you like, but you might
want to think about why some people here are a bit wary of visiting
apparently arbitrary URLs.

--
Richard Heathfield <http://www.cpax.org.uk >
Email: -http://www. +rjh@
"Usenet is a strange place" - dmr 29 July 1999
Jun 27 '08 #8
Bert wrote:
How can my response to this problem be better?
Leave tab characters out of your source code.
The pot doesn't work
that well when you enter 25, 21, 17 and some others.

The problem:

CHRISTMAS TREES

The grade 5 class at the local primary school wants some Christmas
tree outlines to colour in for the break-up session. You have to
write a program which will ask for an odd number representing the size
of the tree, rejecting negative quantities and numbers greater than
sixty, and then draw a tree centrally placed on the printer page
similar to the one below.
*
* *
* *
* *
* *
* *
* *
Base Line--- ***************
*
*
*******
* *
* *
***

The base line of the tree will be made of as many asterisks (*) as the
number that was input, and lines above it will have each of the
outline asterisks move in one space, until the single * appears at the
top.

The pot in which the tree rests should be scaled to suit the tree
size.

Click on treetest
#include <stdio.h>

int main(void)
{
int ts, x, i, j, y, a, z;

printf("Enter the size of the tree: ");
fflush(stdout);
if (scanf("%d", &ts) != 1 || ts % 2 == 0) {
puts("Trees have to be an odd size. An odd number...");
return 0;
}
if (ts < 0) {
puts("Trees can't have a negative size...");
return 0;
}
if (ts 60) {
puts("Trees can't be bigger than 60. Not here anywway...");
return 0;
}
x = ts / 2;
for (i = 0; x i; ++i) {
if (i == 0) {
for (j = 0; x j; ++j) {
putchar(' ');
}
puts("*");
} else {
a = x - i;
for (j = 0; a j; ++j) {
putchar(' ');
}
putchar('*');
a = i * 2 - 1;
for (j = 0; a j; ++j) {
putchar(' ');
}
puts("*");
}
}
for (i = 0; ts i; ++i) {
putchar('*');
}
putchar('\n');
for (i = 0; 2 i; ++i) {
for (j = 0; x j; ++j) {
putchar(' ');
}
puts("*");
}
if (8 ts) {
return 0;
}
a = (ts - x) / 2;
for (i = 0; a i; ++i) {
putchar(' ');
}
x -= x % 2;
a = x + 1;
for (i = 0; a i; ++i) {
putchar('*');
}
putchar('\n');
y = (ts - x) / 2;
for (i = 0; y i ; ++i) {
putchar(' ');
}
putchar('*');
a = x - 1;
for (j = 0; a j; ++j) {
putchar(' ');
}
puts("*");
z = ts / 4 - 2;
for (i = 0; z i; ++i) {
a = 1 + y + i;
for (j = 0; a j; ++j) {
putchar(' ');
}
putchar('*');
a = x - 2 * i - 3;
for (j = 0; a j; ++j) {
putchar(' ');
}
puts("*");
}
a = (ts - 3) / 2;
for(i = 0; a i; ++i) {
putchar(' ');
}
puts("***");
return 0;
}

--
pete
Jun 27 '08 #9

This thread has been closed and replies have been disabled. Please start a new discussion.