Have a program that I've been working on that is supposed to check whether a user inputs valid numbers. In the segment of code that I'm working on, you'll see the numbers, so that's self explanatory.
I think I have a pretty good idea of what I'm doing wrong, but I think it's good to post the whole thing to show my logic and the best way for me to fix it.
Segment of not-working code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
double value;
if (! (value <= 100.0 && value >= 0.0))
{
cout << "Invalid value. Must be between 1 and 100." << endl;
cout << "Program will now terminate. Try again later." << endl;
return 1;
}
else
{
readVector (v1);
readVector (v2);
setOutputDigits (1);
printVectors (v1, "Vector 1 => ");
cout << endl;
printVectors (v2, "Vector 2 => ");
cout << endl;
}
The code is designed to check whether the user inputs a valid floating point number, yet it doesn't actually check. I think it's because value has nothing to do with readVector so the check isn't occurring.
How would I format this code so that it would check the input and terminate when a number such as 101 or -5 is inputted?