Im having some problems doing this simple program.
the reason Im using atof is because the program crashed if I typed anything else other than a number. Now it doesnt crash it just returns 0.
using namespace std;
float result,firstNum, secondNum;
result = firstNum + secondNum;
cout << "\n\t\t\t\t" << result << endl;
cout << "\n\t\t\tEnter First Number: ";
cin >> casting;
firstNum = atof(casting);
cout << "\n\t\t\tEnter Second Number: ";
cin >> casting ;
secondNum = atof(casting);
What I'd like is actually validate the entry and return an error message if the entry is not a number.
I've tried using something like...
...but maybe is not what I need to use (it doesnt work anyway).
while (strcmp(casting, "@*!#&")==1);
cout << "ERROR...only numbers\n";
Is there any simple way to do it? thanks in advance.