![]() |
Creating Isoceles Triangle
I have to write a programme for an isoceles triangle ( two sides equal ) . The programme should ask the user to give the length of base and height . It should be in * characters. And the length of base is always an odd number. If it is not an odd number , triangle shouldnt be drawn. Any help guys ?
I am using Visual Studio with C ++ coding. |
Re: Creating Isoceles Triangle
Where are you stuck?
You need to prompt the user (do you know how to write a message to the screen?) then get a number (do you know how to do that?) twice (once for base and once for height) then for each line (do you know about for loops?) work out the number of spaces to display (can you figure out how to do that?) and the number of asterisks (can you figure it out?) and you're done! Simple. Have a go and see how far you get. Try not to get stuck; think about it instead. If you are really stuck, post the code you've got and we'll see how to get you unstuck. |
Re: Creating Isoceles Triangle
Thanks so much for your help .... I have made a code and everything is going just fine with only last one problem.... I cannot seem to make the triangle correctly..... it shows up inverted....the top vertex is facing downwards... Can you please solve this problem for me and write the code correctly ?
here's my code Code:
#include<stdio.h> |
Re: Creating Isoceles Triangle
Just run the display loop in the opposite direction, i.e.
Code:
for(j=height-1;j>=0;j--) |
Re: Creating Isoceles Triangle
Thanks for that !!! Okay , question ! :)
now i get the triangle right but the problem now persists is when i type 5 as base and 3 height , it displays a perfect triangle , but , when i type 5 as base and 4 as height , it displays the same triangle while it should say that this is not an odd number as required in the question. |
Re: Creating Isoceles Triangle
The question as you've copied it only says the base cannot be even, not the height. However there is a problem in that you don't get the correct height. If you specify 5,6, you get
Code:
*Code:
* |
Re: Creating Isoceles Triangle
I am sorry I miswrote the height and base thing. you are right with your statement. Only base should be odd number and something is going on with the height as well .... Please help me fix it .
An example of a triangle of height 3 and length of its base = 9 Code:
* |
Re: Creating Isoceles Triangle
http://mathworld.wolfram.com/IsoscelesTriangle.html
if you know the length of the base and the height then you can calculate the length of the equal sides of the triangle. check that, the values entered ,are suitable for creating a triangle(the sum of the lengths of any two sides must be greater than the length of the remaining side) |
Re: Creating Isoceles Triangle
sir i really appreciate your help but , allow me to ask , how does it help me with creating the programme ? :)
|
Re: Creating Isoceles Triangle
Quote:
then how you can draw it? and another thing.... if i enter base=3 and height=9 what you draw? |
| All times are GMT +5.5. The time now is 02:34. |