Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Triangle program
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
chocolate thunda




PostPosted: 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
Sponsor
sponsor
Dan




PostPosted: 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




PostPosted: 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




PostPosted: 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




PostPosted: Thu May 13, 2004 9:30 pm   Post subject: (No subject)

That doesn't work either...I tried.
s_climax




PostPosted: Thu May 13, 2004 9:31 pm   Post subject: (No subject)

Then you are using it wrong.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 6 Posts ]
Jump to:   


Style:  
Search: