hello, Im trying to read the contents of "file.txt" and replace each vowel with a corresponding number...help please

#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;
int main()
{
ifstream member;
ofstream dogs;
ofstream cats;
int n=0;
int r=0,f=1,g=2,k=3,p=4,h=5;
string x[100];
int y[100];
dogs.open("file.txt",ios::out);
member.open ("file.txt",ios::in);
cats.open("file2.txt",ios::out);
member>> x[n];
while (x[n]=="a"||x[n]=="e"||x[n]=="i"||x[n]=="o"||x[n]=="u")
{
if(x[n]=="a")
{y[n]=f;}
if(x[n]=="e")
{y[n]=g;}
if(x[n]=="i")
{y[n]=k;}
if(x[n]=="o")
{y[n]=p;}
if(x[n]=="u")
{y[n]=h;}
cout<<y[n] <<"";
n++;
}
member.close();
for(int s=0;s<r;s++)
{cats<<y[s]<<"";}
}
Please post in code tags so that it can be readable.

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

#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;
int main()
{
     ifstream member;
     ofstream dogs;
     ofstream cats;
     int n=0;
     int r=0,f=1,g=2,k=3,p=4,h=5;
     string x[100];
     int y[100];
     dogs.open("file.txt",ios::out);
     member.open ("file.txt",ios::in);
     cats.open("file2.txt",ios::out);
     member>> x[n]; 
     while (x[n]=="a"||x[n]=="e"||x[n]=="i"||x[n]=="o"||x[n]=="u")
    {
         if(x[n]=="a")
        { 
              y[n]=f; 
        }
        if(x[n]=="e")
       {
           y[n]=g;
        }
       if(x[n]=="i")
       {
           y[n]=k;
       }
       if(x[n]=="o")
       {
            y[n]=p;
       }
       if(x[n]=="u")
       {
            y[n]=h;
        }
       cout<<y[n] <<"";
       n++;
   }
    member.close();
    for(int s=0;s<r;s++)
   {
        cats<<y[s]<<"";
   }
}

Oh maaaaaan......
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
57
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;
int main()
{
     ifstream member;
     ofstream dogs;
     ofstream cats;
     int n=0;
     int r=0,f=1,g=2,k=3,p=4,h=5;
     string x[100];
     int y[100];
     dogs.open("file.txt",ios::out);
     member.open ("file.txt",ios::in);
     cats.open("file2.txt",ios::out);
     member>> x[n]; //here you read the first character to x[0]
     while (x[n]=="a"||x[n]=="e"||x[n]=="i"||x[n]=="o"||x[n]=="u")/*here you
     loop untill the first consonant, then stop(if the first character in file.txt isn't
     a vowel it will do nothing*/
    {
         if(x[n]=="a")/*here you check if that character is equal to the memory
         address of the string literal "a"*/
        { 
              y[n]=f; 
        }
        if(x[n]=="e")/*here you check if that character is equal to the memory
         address of the string literal "e"*/
       {
           y[n]=g;
        }
       if(x[n]=="i")/*here you check if that character is equal to the memory
         address of the string literal "i"*/
       {
           y[n]=k;
       }
       if(x[n]=="o")/*here you check if that character is equal to the memory
         address of the string literal "o"*/
       {
            y[n]=p;
       }
       if(x[n]=="u")/*here you check if that character is equal to the memory
         address of the string literal "u"*/
       {
            y[n]=h;
        }
       cout<<y[n] <<"";/* here you output that number and then an empty
       string (numbers will be contancatented(srry for bad english))*/
       n++;/* here you increment n so in the next iteration x[n] will contain
       uninitailzed random data*/
   }
    member.close();
    for(int s=0;s<r;s++)// here you loop from 0 to 0, so nothing happens
   {
        cats<<y[s]<<"";
   }
}

So, based on those errors, I suggest you repost this in the "begginners" section, where those who answer will understand you, and I, I won't lie to you, I just don't have the patiense. Sorry.
PS: You shoual also read this page's tutorial: http://www.cplusplus.com/doc/tutorial/

Errors:

1) Use EOF to check the end of file.

2) Use strcmp for comparing strings.

Ans what does this mean??

" replace each vowel with a corresponding number".

Does it mean the ASCII value??
Does it mean the ASCII value??

No!
f=1,g=2,k=3,p=4,h=5

f, g, p and h are for a, e, i and u, respectivly
Topic archived. No new replies allowed.