Triangle program
Author |
Message |
chocolate thunda
|
Posted: Thu May 13, 2004 8:37 pm Post subject: 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] |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Dan
|
Posted: Thu May 13, 2004 8:49 pm Post subject: (No subject) |
|
|
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:
code: |
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
|
|
Computer Science Canada
Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more! |
|
|
|
|
chocolate thunda
|
Posted: Thu May 13, 2004 9:15 pm Post subject: (No subject) |
|
|
How come this doesn't work?
hyp:=sqrt(l1**2)+(l2**2)
How do you use sqrt?[/code] |
|
|
|
|
|
s_climax
|
Posted: Thu May 13, 2004 9:20 pm Post subject: (No subject) |
|
|
code: |
hyp:=sqrt(l1**2)+(l2**2)
|
should be
code: |
hyp:=sqrt((l1**2)+(l2**2))
|
you needed more brackets. |
|
|
|
|
|
chocolate thunda
|
Posted: Thu May 13, 2004 9:30 pm Post subject: (No subject) |
|
|
That doesn't work either...I tried. |
|
|
|
|
|
s_climax
|
Posted: Thu May 13, 2004 9:31 pm Post subject: (No subject) |
|
|
Then you are using it wrong. |
|
|
|
|
|
|
|