Question: Complete/modify the code so that the C++ program will produce output similar to the following (formatted to 2 decimal places). Compile and debug the program
Complete/modify the code so that the C++ program will produce output similar to the following (formatted to 2 decimal places). Compile and debug the program until there are no syntax, runtime, or logic errors. Remember that two or more data items can be input at one time by having at least one blank space between them before hitting the enter key. Pythagorean Theorem says that for a right triangle with sides a and b, then a^2 + b^2 = c^2, where c is the hypotenuse. Solving for c, we get c = sqrt((a * a) + (b * b)).
Pracrice run: Please enter the values for the two sides of a right triangle: 9 3 The sides of the right triangle are 9.00 and 3.00 The hypotenuse for this triangle is 9.49
#include #include //library for formatting output #include //needed for math functions like sqrt() using namespace std; int main() { //declare variables double a, b; // the smaller two sides of the triangle double c; // the hypotenuse calculated by the program //set up formatting //prompt user for inputs cout << "Please enter the values for the two sides of a right triangle: "; cin >> a >> b; // Fill in the assignment statement that determines the hypotenuse //display results cout << "The sides of the right triangle are " << a << " and " << b << endl; cout << "The hypotenuse for this triangle is " << c << endl; return 0; } //end main()
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
