I am creating a simple area calculator that exhibit overloading. I already finished the overloading function, my concern is, I want to key trap the pressed letters/characters by the user. I want to allow only numbers (int & float data type) input. How will I do that? Thanks. I am using Dev C++.
Here is some part of my code:
if (yourchoice ==1){
cout << "\n---- Area of Square ----";
cout <<"\nSide of Square: ";
cin >> SqSide;
int AreaSquare=area(SqSide);
cout<<"\n Area of a Square is = "<<AreaSquare << endl;
}else if (yourchoice ==2){
cout << "\n---- Area of Rectangle ----\n";
cout <<"Length of the Rectangle: ";
cin >> length;
cout <<"\nWidth of the Width: ";
cin >> width;
int AreaRectangle=area(length, width);
cout<<"\n Area of Rectangle is = "<<AreaRectangle << endl;
When the user cin a letter/character, I want the program to prompt that the user inputted a wrong input. If the user cin a number/numbers, the program will proceed to the function and calculate the area.