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.
#include <iostream>
#include <cmath>
usingnamespace 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;
}