I am creating a program that I want the user to be able to add more 'money' to their account. They would be entering how much money they want to add to it.
So after the user has entered how much money they want to add to their account, I want to check if a valid input has been entered (a number and not a character) and if a number has been added, the program continues like normal, but if not then it will output a message to the user.
I have tried something like this to get the users input and try to check it. (userMoney
and userMoneyAdd
are both float
)
cout << "Enter the amount of money you want to enter in £'s" << endl;
cin >> userMoneyAdd;
cout << "You entered " << userMoneyAdd << endl;
if (userMoneyAdd == (int)userMoneyAdd) {
cout << "you entered a number" << endl;
}
else {
cout << "You have not entered a number" << endl;
}