Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
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]

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.
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 1  [ 6 Posts ]
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: