Ok, I'm still new at this, so bear with me...
I have a question with regards to the code below:
# include <iostream>
# include <string>
using namespace std;
double test;
int main()
{
do
{
cout << "Test to see if a number is between 0 and 1000:" << endl;
cin >> test;
if (test >= 1000)
{
cout << "NUMBER IS GREATER THAN 1000!!!" << endl;
}
else if (test <= 0)
{
cout << "THE NUMBER IS LESS THAN 0!!!" << endl;
}
}
while ((test >= 1000) || (test <= 0));
cout << "The following number is between 0 and 1000: " << test << endl;
cout << endl;
cout << "Done" << endl;
return 0;
}
If the user "accidental ly" enters a letter instead of a number, the program goes nuts!!!
How do I account this possible user entry error?
Thanks,
Terence
I have a question with regards to the code below:
# include <iostream>
# include <string>
using namespace std;
double test;
int main()
{
do
{
cout << "Test to see if a number is between 0 and 1000:" << endl;
cin >> test;
if (test >= 1000)
{
cout << "NUMBER IS GREATER THAN 1000!!!" << endl;
}
else if (test <= 0)
{
cout << "THE NUMBER IS LESS THAN 0!!!" << endl;
}
}
while ((test >= 1000) || (test <= 0));
cout << "The following number is between 0 and 1000: " << test << endl;
cout << endl;
cout << "Done" << endl;
return 0;
}
If the user "accidental ly" enters a letter instead of a number, the program goes nuts!!!
How do I account this possible user entry error?
Thanks,
Terence
Comment