Explore BrainMass
Share

Inputting Multiple Integers in a Form

This content was STOLEN from BrainMass.com - View the original, and get the already-completed solution here!

The sum of the lengths of any two sides of a triangle must be greater than the length of the third side. For example, the numbers 3, 4, and 5 can form a triangle because 3+4 > 5, 4+5 > 3, and 5+3 > 4. In contrast, the numbers 1, 2, and 5 cannot form a triangle because 1+2 < 5. Thus, if you are given any three integers, you can determine whether they could possibly form a triangle or not by applying this general principle.

Write a JavaScript program that allows a user to input three integers using text boxes in a form. (Hint: You need to use the built-in parseInt function to convert the input strings to integers.) Test the three integers to determine if they can be formed into a triangle using the rule given above. Also test if the resulting triangle would be a right triangle using the Pythagorean theorem, namely that the square of the hypotenuse (the longest side) equals the sum of squares of the other two sides. Display an alert box to inform the user whether their integers can form a triangle or a right triangle (tell them which), or if the integers cannot form a triangle. Continue accepting sets of three integers and testing them until the user decides to quit.

© BrainMass Inc. brainmass.com October 25, 2018, 8:21 am ad1c9bdddf
https://brainmass.com/computer-science/javascript/inputting-multiple-integers-form-537019

Solution Summary

The input multiple integers in a form are examined. The expert writes a JavaScript function.

$2.19
See Also This Related BrainMass Solution

C++ program to determine if 3 numbers form a triangle

Write a C++ program that reads in three integers representing line lengths, and determines if the three line segments form a right triangle. If it is not a right triangle, is it a valid triangle. Allow the three numbers to be input in any order. An input number 'n' will be in the range [1,5000]. The program should read the data from a file called triangleFile.dat and then write the results into an output file.

Attached Word document (named as TriangleFile.dat) contains following test data.

3 4 5
55 25 25
20 48 52
123 345 299
2002 4001 1050
441 588 735
4999 4999 4999
648 702 270
100 200 500
88 50 60
72 120 48
75 60 45
1000 50 1100

View Full Posting Details