This is definitely a homework problem, so hopefully I don't get some ToS breach warning, but I can't seem to find any help in reference as to why I keep having problems. I'm not looking for a solution or hand out, but moreso explanation as to why the loop goes berserk. I can't seem to find any explanation on the subject of loops and switch statements to clarify what I'm doing wrong.
Whatever I do, it seems to either,
A. repeat infinitely crazy when I enter a non-numeric character at the end, or
B. refuses to exit when I enter 1.
As of now it falls under B. I'm not sure if it's how I'm initializing the variable for the switch, since I do get notifications in some cases that I haven't initialized the switch variable. Or perhaps it's a restriction on the nature of the switch statement itself. I'm not sure.
Here's the code:
#include<iostream> // Required for cout.
#include<cmath> // Required for math computations functions.
using namespace std;
const double PI = acos(-1.0);
int main()
{
// Declare objects.
double X, Y, magnitude, angle, angle_deg;
char reply;
// Destination for loop.
do
{
// Prompt user for input
cout << "Please enter a value for x: " <<endl;
cin >> X;
cout << "Now enter a value for y, please: " <<endl;
cin >> Y;
// Converting radians to degrees.
angle_deg = angle*(180/PI);
// Print magnitude and angle.
cout << "The magnitude of the vector is: "
<< magnitude << endl;
cout << "The angle of the vector in degrees is: "
<< angle_deg << endl;
cout << "The angle measured in radians is: "
<< angle << endl;
// Prompt to either continue or exit program.
cout << "Evaluate another vector?" <<endl
<<"Enter 1 and ENTER to exit or any key and ENTER to continue:" <<endl;
cin >> reply;
in the switch control structure if you are comparing chars you need to include the 'apostrophe, otherwise the compiler assumes the case to be a number.