Hey there. I am new to this forum, just joined, and am here to learn from others and hopefully help others if I can.

I am taking a 'fundamentals of programming course at a community college. I have been studying the book 'C++ Programming' by D.S. Malik, sixth edition.

Recently in my class, we had to create different simplistic switch statements and if else statements. Knowing this, the first task was to have the user enter two integers. After getting the two integers (via a couple 'cin >>' variable calls), then the user was to input a number or letter that coincided with their choice for what arithmetic process they wanted the numbers to undergo. What I wanted to do, though I wasn't supposed to do it since I was farther ahead in understanding than the class, was to create a fail-safe whereas if the user inputs a letter/character instead of a number at the beginning, the program would end and prompt the user to close the program and begin again. I did not write the code in question, but found it off of the internet. I will paste half of my code below (the other half of it doesn't pertain to this issue). Any ideas anyone? Thank you so much for your time and effort! If there are any questions pertaining to my code (like if I've left something out that you need to see to be able to fully analyze my problem) don't hesitate to let me know and I'll give it to you or explain it further.


Thank you so much again everyone and I really appreciate it!


#include <iostream>
#include <iomanip>
#include <cmath>
#include <limits>

using namespace std;

int main() {
double x;
double y;
char (op);
char (ch);
double result;

cout << "Hello User!" << endl;
cout << "Please input 2 numbers and hit enter." << endl;
cin >> x;
cin >> y;

//Code below was 'fail-safe' code I was trying to implement, but failed.
while(!(cin >> x, y))
{
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
cout <<"This is not an applicable input. Please restart program and try again."<< endl << endl;
return 1;
}

cout << "Please select one of 4 processes below to utilize to manipulate your \ntwo numbers: " << endl;
cout << "By typing 'a', you will add the two numbers. \nBy typing 's' you will subtract the two numbers." <<
"\nBy typing 'm', you will multiply the two numbers. \nBy typing 'd', you will divide the two numbers." << endl;
cin >> ch;

if (ch == 'a' || ch == 'A'){
result = x + y;
cout << "Your result is: " << result << endl;
}
else if (ch == 's' || ch == 'S'){
result = x - y;
cout << "Your result is: " << result << endl;
}
else if (ch == 'm' || ch == 'M'){
result = x * y;
cout << "Your result is: " << result << endl;
}
else if (ch == 'd' || ch == 'D'){
result = x / y;
cout << "Your result is: " << result << endl;
}
cout << endl;