Using the Pythagorean Theorem, calculate the hypotenuse of a right triangle give
ID: 3813171 • Letter: U
Question
Using the Pythagorean Theorem, calculate the hypotenuse of a right triangle given the length of the two shorter sides. Be certain to use the square and square Root functions from the Gentle Introduction textbook. (You will need to change the square function to use floating point numbers though.) Ask he user if s/ he wants to keep entering data; if "Yes" then continue prompting and calculating Assume no sides are negative. Solving this might involve some research on your part! Use the following sample as a guide Enter side A: 3 Enter side B: 4 Side C is 5 Continue? yes Enter side A: 33 Enter side B: 44 Side C is 55 Continue noExplanation / Answer
please refer below code
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
string choice = "yes";
double A,B,C;
do
{
cout<<"Enter side A : ";
cin>>A;
cout<<" Enter side B : ";
cin>>B;
C = sqrt((A * A) + (B * B)); //using Pythagoras theorem
cout<<" Side C is "<<C<<endl;
cout<<"Continue? ";
cin>>choice;
}while(!choice.compare("yes")); //comparing with "yes" if equal then execute loop
return 0;
}
please refer below output
Enter side A : 3
Enter side B : 4
Side C is 5
Continue? yes
Enter side A : 33
Enter side B : 44
Side C is 55
Continue? no
Process returned 0 (0x0) execution time : 19.542 s
Press any key to continue.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.