Having trouble running a do while with a if else statement. I'm getting an error saying the "variable 'distanceM' is being used without being initialized."
int main ()
{
const double PI = 3.141592;
double xM, yTheta, distanceM, thetaRad, thetaDeg, xRad, yRad, X, Y;
char choice;
cout << "This program converts a set of polar coordinates ( M , theta in degrees ) to" << endl;
cout << "their rectangular equivalents ( x, y), or a set of of rectangular coordinates" << endl;
cout << "to their polar equivalents." << endl;
cout << "\nEnter the first coordinate ( x or M): ";
cin >> xM;
cout << "Enter the second coordinate ( y or theta ): ";
cin >> yTheta;
cout << "Enter r or R if these are Rectangular";
cout << "\nor p or P if they are polar: ";
cin >> choice;
do
{
if ( 'r' == choice)
{
distanceM = sqrt((pow(xM,2))+(pow(yTheta,2)));
thetaRad = atan(yTheta/xM);
thetaDeg = (thetaRad) * (180/PI);
cout << "\nThe Polar Coordinates ( M, theta ) are ( "<< fixed << setprecision(2) << distanceM <<" , "<< thetaDeg <<" )";
}
else if ( 'p' == choice)
{
xRad = (yTheta)*(PI/180);
yRad = (yTheta)*(PI/180);
X = distanceM*(cos(xRad));
Y = distanceM*(sin(yRad));
cout << "\nThe Rectangular Coordinates ( x, y ) pair is ( "<< fixed << setprecision(2) << X <<" , "<<Y<<" )";
}
else
break;
} while(1);
getchar ();
return (0);
}
Can anyone help me out?