Ratio not working

#include <iostream>
#include <cmath>
using namespace std;
double ratio, display, width, a, b;

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

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

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

ratio = a / b

width = ratio * height

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

return 0;

}
Last edited on
EDIT: The initial code was edited from obtaining a ratio to the Pythagorean theorem.

Is the formula to obtain ratio is correct? Your program is running and producing the output based on what you code.

A couple of points:
1. I would avoid using global variables (if possible).
2. You ask about inputting the width value to a variable a. However, you have a width variable available.
3. I would write in a piece of paper the algorithm to obtain ratio and then try to see if it matches. I placed in the comment the values I inputted in the code.

Good luck!


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
#include <cmath>
using namespace std;
double ratio, width, a, b;

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

	cout << "Enter the height value of the display ratio: ";
	cin >> b; // User input 18

	ratio = a / b; // Radio = 9 / 18 = 0.5

	width = ratio * b; // width = 0.5 * 18 = 9

	cout << "Your TV has a width of " << width << " inches" << endl; // width = 9.

	return 0;
}
Last edited on
Just to give you an idea about the to 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.