Pythagorean theorem help

#include <iostream>
#include <cmath>
using namespace std;
double a, b, c, width, height;

int main()
{
cout << "Enter the width value of the display ratio: ";
cin >> a;

cout << "Enter the height value of the display ratio: ";
cin >> b;

cout << "Enter the diagonal of the display in inches: ";
cin >> c;

width = pow(c, 2) + pow(b, 2);
width = sqrt(width);

height = pow(c, 2) + pow(a, 2);
height = sqrt(height);

cout << "Your TV has a width of " << width << " inches" << " and a
height of " << height << " inches" << endl;

return 0;

}

// I just need a little push in the right direction, the Pythagorean theorem is not working.
Last edited on
To give you an idea about how to do the Pythagorean theorem.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>
#include <cmath>

int main()
{
	// a2 + b2 = c2

	// obtain a (Heigth)
	double height{};
	std::cout << "Height: ";
	std::cin >> height;

	// obtain b (Length)
	double length{};
	std::cout << "Length: ";
	std::cin >> length;

	// obtain a2 by using the pow function.
	const double heightExp2{ std::pow(height,2) };
	// obtain b2 by using the pow function.
	const double lengthExp2{ std::pow(length, 2) };
	// obtain c2 by adding a2 + b2
	const double diagonExp2{ heightExp2 + lengthExp2 };
	// obtain c by using the square root function and display it to the console.
	std::cout << "Diagonal Measurement is: " << std::sqrt(diagonExp2) << std::endl;

	return 0;
}
Topic archived. No new replies allowed.