[My program will not loop and my I dont know what is wrong with my math for REC -> POL][1]
-If the character is a P/p, the two floating point numbers should be interpreted as a set of Polar Coordinates and the program should first calculate the Rectangular Coordinate equivalent and then display both the Rectangular Coordinate and Polar Coordinate values.
-The program should continuously read sets of coordinate values until a Q/q (quit) is entered. -A set of coordinate values consist of a single character follow ed by two floating point numbers. The single character can be an R/r or a P/p. If the character is an R/r, the two floating point numbers should be interpreted as a set of Rectangular Coordinates and the program should first calculate the Polar Coordinate equivalent and then display both the Rectangular Coordinate and Polar Coordinate values.
If any other character other than R/r, P/p, or Q/q is entered, the program should display an error message. Note the program needs to do two “dummy” reads to disregard the two coordinate values following the illegal character. In the example below, after the illegal ‘d’ character is detected, the program had to read, and disregard, the 99.9 and 11.1 following the ‘d’. Likewise for the illegal ‘L’ input
int main() {
double x;
double y;
double M;
double th;
char input;
cin >> input;
cin >> x >> y;
while ((input != 'q') && (input != 'Q')) {
if ((input == 'r') || (input == 'R')) {
M = sqrt((x*x) + (y*y));
th = atan2(y, x);
x = M * cos(th);
y = M * sin(th);
th = th * (180 / M_PI);
cout << "POL -> REC: REC: X = " << x << " Y = " << y << " POL: M = " << M << " A = " << th << endl;
cin >> input >> x >> y;
}
if ((input == 'p') || (input == 'P')) {
th = atan2(y, x);
M = sqrt((x*x) + (y*y));
M = M * (180 / M_PI);
th = th * (180 / M_PI);
x = M * cos(th);
y = M * sin(th);
x = x * (M_PI / 180);
y = x * (M_PI / 180);
cout << "REC -> POL: REC: X = " << x << " Y = " << y << " POL: M = " << M << " A = " << th << endl;
cin >> input >> x >> y;
}
if ((input != 'r') && (input != 'R') && (input != 'p') && (input != 'P')) {
cout << "Format Error!" << endl;
cin >> input >> x >> y;
}
cin >> input >> x >> y;
return 0;
}
}