Problem with reading input.

Hey guys. i am trying to write a program which will read input from a text file, check if each line contains any alphabets and then display a message imforming me if there is an alphabet in each line. My text file is formatted in this way...

1
2
3
4
123
562
red
21e

Based on this example, the expected output of my program would be..

1
2
3
4
No alphabets!
No alphabets!
Aplhabets!
Alphabets!


Here the coding which i have done...
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
class CheckType
{
public :
    int CheckNumeral (string&) ;
private :

};

#include <stdlib.h>
#include "header.h"


 int CheckType::CheckNumeral(string&num)

 {

     int check = 0 ;
   for (int i = 0; i<num.size(); i++) {
       if (!isdigit(num[i])){
        
           check = 1;
       if (check = 1)
           cout << "Alphabets!" << endl;
          num = "";
           check = 0;       
       }   
       else {
          cout << "No alphabets!"<< endl;
   num = "";
   check = 0;
       }
       num = "";
   }
 }


int main()
{
    fstream readFile("Testing.txt");

    if (readFile.is_open())
    {

    string templine ;
    CheckType ct ;
  //  ofstream myfile;
// myfile.open ("New.txt");

while (getline(readFile,templine))
{
  
ct.CheckNumeral(templine);

    }
    }
}



Based on my coding now , when i the text file has data like this...

1
2
3
111
222
red

I will get the correct output which is...

1
2
3
No Alphabets!
No Alphabets!
Alphabets!


but when my text file has data like this...

1
2
3
4
111
222
red
1r


I would get an output which says...

1
2
3
4
No Alphabets!
No Alphabets!
Alphabets!
No Alphabets!


I been trying out different ways to figure it out. Hope for some help in pointing out where the mistake is please.
I believe what you want to say in line 22 is if (check == 1)
Consider switching the order of the statement as a general practice. If you had written the following line of code the compiler would have helped you.

1
2
3
4
5
6
7
// This won't compile
if(1 = check)

// this compiles but is wrong and results in unexepected run-time behavior.
// The result of the expression is 1 so the test is always true because check is 
// assigned the value of 1
if(check = 1)
Topic archived. No new replies allowed.