Can you post your edited code and verbatim error message? cin.clear() is not a new concept as far as compilers go, although Dev C++ is known to have problems...
Knowing how to interpret and fix error messages is an important skill in C++.
You also have poor indentation.
1 2 3
|
else
cout<<"Enter the Secondary Factor limit:";
cin>>j;
|
This else statement is only being applied to the cout line. I'm not sure if that's what you want. Probably not.
isdigit is not doing what you think it's doing. isdigit works on a single character, say, '2' (note: different than the number 2), and returns true if the character is a digit character ('0', '1', '2' ... '9').
isdigit('a') --> returns false
isdigit('3') --> returns true
Andy's code should be fine, but if you still can't get it to work, this should work almost as well.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
#include<iostream>
#include<ctype.h>
using namespace std;
int main()
{
char yn;
do
{
int factor1;
int factor2;
cout << "Enter Primary Factor: ";
if (!(cin >> factor1))
{
cout << "Error. Please enter a digit";
return 1;
}
cout << "Enter the Secondary Factor limit: ";
if (!(cin >> factor2))
{
cout << "Error. Please enter a digit";
return 1;
}
for (int i = 0; i <= factor2; i++)
{
cout << factor1<< "x" << i << "=" << factor1*i << endl;
}
cout << "\nEnter new table(y/n)?";
cin >> yn;
} while (yn != 'n');
return 0;
}
|