-----------------------------------
chocolate thunda
Thu May 13, 2004 8:37 pm
Triangle program
-----------------------------------
I am asked to write a program that asks the user to enter the 2 lengths of a right triangle and make the user guess the length of the hypotenuse.
Then the program has to calculate the hypotenuse, and ask the user again for four times in a row.
If the user fails to get it right in four chances than the program should exit.
This is what I tried:
var l1,l2,hyp:int
put"Enter the lengths of 2 sides of a right angle:"
get l1,l2
put l1,l2
hyp:=sqrt((l1**2)+(l2**2))
put "Enter the estimated value of the hypotenuse:"
get hyp
after this I am stuck, does anyone know how to continue?[/list]
-----------------------------------
Dan
Thu May 13, 2004 8:49 pm
-----------------------------------
well for staters you can not uses var hyp 2 times like that. The value of hyp is being replaced with the users input.
what you whont is an if stament like this:
put "Enter the estimated value of the hypotenuse:"
get ans
if ans = hyp then
put "that is right"
else
put "that is wrong"
end if
-----------------------------------
chocolate thunda
Thu May 13, 2004 9:15 pm
-----------------------------------
How come this doesn't work?
hyp:=sqrt(l1**2)+(l2**2)
How do you use sqrt?[/code]
-----------------------------------
s_climax
Thu May 13, 2004 9:20 pm
-----------------------------------
hyp:=sqrt(l1**2)+(l2**2)
should be
hyp:=sqrt((l1**2)+(l2**2))
you needed more brackets.
-----------------------------------
chocolate thunda
Thu May 13, 2004 9:30 pm
-----------------------------------
That doesn't work either...I tried.
-----------------------------------
s_climax
Thu May 13, 2004 9:31 pm
-----------------------------------
Then you are using it wrong.