Hi! i was wondering how I could make sure that the user inputs the proper values in my code. I've been looking online and seen things like cin.good() and cin.fail() but the explanations aren't really straightforward and a little confusing. I was wondering if anyone could help me implement the proper input validation for my code. thanks so much!
#include <iostream>
using namespace std;
int main()
{
double *num1ptr = new double;
double *num2ptr = new double;
char *oprptr = new char;
double *solptr = new double;
cout << "This program will add, subtract, multiply, or divide two"
<<" numbers inputted by the user." << endl;
cout << "Please enter first number: ";
cin >> *num1ptr;
cout << "Please enter second number: ";
cin >> *num2ptr;
cout << "Enter the operation you would like to perform (to add use +,"
<< " to subtract use -, to multiply use *, to divide use /): ";
cin >> *oprptr;
switch(*oprptr)
{
case '+':
*solptr = *num1ptr + *num2ptr;
break;
case '-':
*solptr = *num1ptr - *num2ptr;
break;
case '*':
*solptr = *num1ptr * *num2ptr;
break;
case '/':
*solptr = *num1ptr / *num2ptr;
break;
default:
cout << "Invalid Operator Inputted" <<endl;
break;
}
cout <<"Solution of "<<*num1ptr<<" "<<*oprptr<<" "<<*num2ptr
<<" = "<<*solptr<<endl;
}