The facts:
I’m using the cin bit (command? function?) to capture a number from the user. That part I’m fine with. But next I want to verify that what I’ve captured is really a number, and if it isn’t respond with an admonishment through cout. I’m fine with the cout syntax too; it’s just the verifying part that I haven’t got. I assume it look ssomething like this:
if (somethingsomething)
{
cout << “Admonishment” << endl;
}
or
if (somethingsomething)
{
cout << “Andmonishment. Instruction to input appropriate value.” << endl;
cin >> variablename;
}
But the somethingsomething part I don’t know.
I’m using codewarrior (which a friend gave to me), but what I know about c++ is what I remember from an intro c/matlab class two years ago and what I’ve figured out from experimentation in the last 9 hours. So go slowly, please.
The questions:
- Is what I’ve guessed above right?
- If so, what should I place instead of somethingsomething?
- Does assigning a double or int variable preclude capturing anything else? Does that require a string?
3a) If I were to ask for a string, how would I go about verifying that it’s an acceptable one (such as an actual filename or somesuch)? - How can I make the admonishment repeat until I get an acceptable number? Do I need a for loop?
I’ve tried google, but I can’t find anything about verifying strings or numbers. Lots of sites about basic syntax, though.