### Problem with loops and void

Greetings, this is an assignment which the purpose is too calculate an angle value in form of trigonometric functions. These are the codes that I've wrote so far.

 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586`` ``````#include #include using namespace std; void menu(double &value) { system("cls"); cout<<"*****Trigonometry Program*****"< "; cin>>value; } void choice() { cout<<" Type D if it is in Degree"< "; } void degree(bool &stopSystem2, double value) { cout< "; } int main() { double value; char degOrRad; char noContinue; bool stopSystem1=false; while (!stopSystem1) { menu(value); cout<<"Is the angle in Degree or Radian?"<>degOrRad; degOrRad=toupper(degOrRad); switch (degOrRad) { case 'D' : degree(stopSystem2, value); break; case 'R' : radian(stopSystem2, value); break; default : cout<<"Invalid response, try again!"<>noContinue; if((noContinue!='Y') && (noContinue!='y')) { stopSystem1=true; } else { } } cout<<"Thank you, goodbye!!"<

I have completed the codes for the interface part. Before I proceed with the formula for the trigonometric functions, I would like to make sure the program is Error-free, which if there is accidental invalid input from the user, the program would the user to enter another input until it is a valid response.

The only problem I have encountered for this matter was in `menu(value)`

If I enter an integer, the program will proceed without error. However, If I enter a character, the program will slip into an endless loop which constantly shows this
 ``12345678910`` ``````*****Trigonometry Program***** Please enter an angle value => Is the angle in Degree or Radian? Type D if it is in Degree Type R if it is in Radian Your response=> 0 //my initial input for value Do you want to continue? Type Y to continue Type any other key to stop Your response =>``````

Can anyone tell me where is the source of the problem? I'm pretty sure it's the loop, but I don't know what to do.
input steam became corrupted after trying to assign string to `double` type. Because of that, another use of `cin`, wont work, thus `degOrRad` will never change and while loop will never end.

here is a little code i wrote:
 ``1234567891011121314151617181920212223242526272829303132`` ``````#include using namespace std; int main() { double value; char retry=0; do { retry =0; system("cls"); cout << "enter value:" << endl; cin >> value; if (cin.fail()) //this is code that should interest you { //read details about it on this site cout << "Non-numerical value entered!" <> retry; } while (retry=='y' || retry == 'Y'); system("pause"); return 0; }``````

experiment with it to fix your problem.

edit:
test it with number and letter as an input
Last edited on
Thank you! :D
Topic archived. No new replies allowed.