What's wrong with this code? ... please help :( | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

What's wrong with this code? ... please help :(

#include <iostream> #include <cmath> // needed for math functions like sqrt() #include <iomanip> using namespace std; int main() { float a, b; // the smaller two sides of the triangle float hyp; // the hypotenuse calculated by the program cout << "Please input the value of the two sides" << endl; cin >> a >> b; hyp = sqrt(exp(a) + exp(b)); // Fill in the assignment statement that determines the hypotenuse. cout << setprecision(2) << fixed << showpoint; cout << "The sides of the right triangle are " << a << " and " << b << endl; cout << "The hypotenuse is " << hyp << endl; return 0; } ----------------------- I put in the value of two sides: 9 3 I expected the output of hyp is 9.49 but I got 90.13 .... How can I fix it? :(

5th Mar 2017, 2:46 PM
Luke Mai
Luke Mai - avatar
1 Answer
+ 1
it's not exp(a)+exp(b) it is pow(a,2)+pow(b,2) I think there is no need for cout << setprecision(2) << fixed << showpoint;
5th Mar 2017, 3:12 PM
vishnu
vishnu - avatar