Hey guys. I am trying to write a program which will read data from a text file and then check if the data contains only numerals or not.
My text file is basically in this format...
Basically, the expected output of my program is that it will check the data and then tell me if the data is in numbers only or not. For this example, the output should be
Here is my coding
cpp file
Code:
int CheckType:: CheckNumeral(string& num)
{
int a;
int b;
for (int i = 0; i < num.length(); i++) {
if (!isdigit(num[i]))
return 1;
}
return 3;
}
main
Code:
int main()
{
fstream readFile("Note.txt");
string templine ;
string line ;
CheckType ct ;
while (getline(readFile,templine))
{
if (templine != " "){
ct.CheckNumeral(templine);
if (ct.CheckNumeral(templine)== 3){
cout<<"yes!"<<endl;
}else if(ct.CheckNumeral(templine)== 1){
cout<<"no"<<endl;
}
else{
cout << "do not know"<< endl;
}
}
else
{
cout << "i am done" << endl;
}
Header file
Code:
using namespace std ;
class CheckType
{
public :
int CheckNumeral (string& ) ;
private :
};
Using the prog i wrote , the output i get when i run the example text will be...
Can sombody help me to identify the problem and tell me what might be the problem? hope for some help. Thanks