Major C++ noob here, as well as programming in general.
I am making a very simple tax calculator and I am wondering if it is possible to prevent a user from inputting values that are not numeric. I don't want to validate the input to see if it is numeric or not. I am strictly trying to prevent the invalid input from showing up in the first place. I'm not sure if I wasn't thorough enough when searching but I couldn't find anything about this anywhere else which makes me think it is possible.
Ex. I am the user, I hold down the 'a' key, nothing shows up
I am the user, I hold down the '}' key, nothing shows up
I press '1', '2', and '3', 123 shows up in program.
Thank you in advance for help.
#include <iostream>
using namespace std;
int main()
{
double mealCost, taxAmount;
double tipAmount, totalAmount;
const double TAX_RATE = .0675;
const double TIP_RATE = .20;
cout << "\nRestaurant Bill Calculation\n" << endl;
// Input
cout << "\nEnter the cost of your meal" << endl;
cin >> mealCost;
// Processing
taxAmount = TAX_RATE * mealCost;
tipAmount = (taxAmount + mealCost) * TIP_RATE;
totalAmount = mealCost + taxAmount + tipAmount;
// Output
cout << "Meal cost " << mealCost << endl;
cout << "Tax Amount " << taxAmount << endl;
cout << "Tip Amount " << tipAmount << endl;
cout << "Total Amount " << totalAmount << endl;
return 0;
}