Forums Register Login

Help with a simple pyrimid program

+Pie Number of slices to send: Send
I was learning Java and there was this exersize to construct a simple pyramid of prespecified height and width. The program i wrote is turining up with the wrong result. Any help would be much apreciated.





+Pie Number of slices to send: Send
What's the result and what's wrong with it?
+Pie Number of slices to send: Send
 

Knute Snortum wrote:What's the result and what's wrong with it?


There is a single rectangle in the applet window with 2 separate rectangles right at the top such that you can see only their bases.
+Pie Number of slices to send: Send
Sounds like something's wrong with "y".

Are these statements doing what you want?

y=-BRICK_HEIGHT;
x=-(BRICK_WIDTH/2);
+Pie Number of slices to send: Send
 

Knute Snortum wrote:Sounds like something's wrong with "y".

Are these statements doing what you want?

y=-BRICK_HEIGHT;
x=-(BRICK_WIDTH/2);



I difinitely use BRICK_HEIGHT. dont know why the underscore didnt get printed but i used the correct version.
+Pie Number of slices to send: Send
Review where you use a = a - SOMETHING and where you use a = -SOMETHING, where "a" is any variable. Are the values really what you want?

Keep this in mind:

a = a - SOMETHING;

is the same as

a -= SOMETHING;

but not

a = -SOMETHING;
+Pie Number of slices to send: Send
 

Knute Snortum wrote:Review where you use a = a - SOMETHING and where you use a = -SOMETHING, where "a" is any variable. Are the values really what you want?

Keep this in mind:

a = a - SOMETHING;

is the same as

a -= SOMETHING;

but not

a = -SOMETHING;




Yes. Got you.

But the program still doesnt work. Now there isnt a single rectangle on screen.
+Pie Number of slices to send: Send
At this point I'd focus on getting one brick in the right place. Comment out the other code or start another program.

Then think about what is happening to x and y. x++ is to the right; x-- is to the left; y++ is up; y-- is down. Get two bricks in the right place, and so on.

Also, post your code.
+Pie Number of slices to send: Send
 

Knute Snortum wrote:At this point I'd focus on getting one brick in the right place. Comment out the other code or start another program.

Then think about what is happening to x and y. x++ is to the right; x-- is to the left; y++ is up; y-- is down. Get two bricks in the right place, and so on.

Also, post your code.


Got the program to work. Weirdly it wasnt on the screen even in fullscreen but i had to scroll right to the bottom of the window where the pyamid was.

Your help was much appreciated thanks.

on a related topic, while working on programming a microcontrller i could debug the program line by line. Is it possible in eclipse too? Where can i find information about that. Thanks again.
+Pie Number of slices to send: Send
That is how do i debug the program line by line?
+Pie Number of slices to send: Send
In Eclipse, look for the bug icon or next to Run as is a menu item Debug as. You have to set a break point but then you can step thru the program.
Sometimes you feel like a nut. Sometimes you feel like a tiny ad.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 523 times.
Similar Threads
The pyramid attacks!
For Loops making me loopy
Newbie stuck on Pyramid Program
Question about building a pyramid
Need help with code
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 05:29:28.