Pig Latin

When i excute the program it doesnt pick up my file and i cant find out what i am missing.
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
 #include <iostream>
#include <string>
#include <fstream>


using namespace std;

bool isVowel(char);
string rotate(string);
string plString(string);

int main()
{ 
	string str;
	cout << "Enter a string: ";
	cin >> str;
	cout << endl;
	cout << str << " in pig latin = " << plString(str) << endl;

	
	ifstream infile;
	infile.open("input.txt");
	infile >> str;
	while(infile)
	{
		cout << plString(str) << " ";
		infile >> str;
	}
	cout << endl;
	system("pause");
	return 0;
}


bool isVowel(char ch)
{
    switch (ch)
    {
    case 'A':
    case 'E':
    case 'I':
    case 'O':
    case 'U':
    case 'Y':
    case 'a':
    case 'e':
    case 'i':
    case 'o':
    case 'u':
    case 'y':
        return true;
    default:
        return false;
    }
}

string rotate(string str)
{
    string::size_type len = str.length();

    string str1;

    str1 = str.substr(1, len - 1) + str[0];

    return str1;
}

string plString(string str)
{
    string::size_type len;

    bool Vowel;

    string::size_type counter;

    if (isVowel(str[0]))                       //Step 1
        str = str + "-yay";
    else                                        //Step 2
    {
        str = str + '-';
        str = rotate(str);                    //Step 3

        len = str.length();                    //Step 3.a
        Vowel = false;                     //Step 3.b

        for (counter = 1; counter < len - 1;
                          counter++)            //Step 3.d
            if (isVowel(str[0]))
            {
               Vowel = true;
                break;
            }
            else                                //Step 3.c
                str = rotate(str);

        if (!Vowel)                        //Step 4
            str = str.substr(1, len) + "-way";
        else
            str = str + "ay";
    }

    return str;                                //Step 5
}
check to see if your file is open.

If there are spaces in your file, it's probably not doing what you think it is.
Last edited on
Sorry i dont know much about files... How would i do that?
Okay so i figured out what was happening with my file. How would i output the converted sentences to a output file?


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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include <iostream>
#include <string>
#include <fstream>


using namespace std;

bool isVowel(char);
string rotate(string);
string plString(string);

int main()
{ 

	string str;
	ifstream infile;
	infile.open("input.txt");
	infile >> str;
	while(infile)
	{
		cout << plString(str) << " ";
		infile >> str;
	}
	cout << endl;
	system("pause");
	return 0;

}
	



bool isVowel(char ch)
{
    switch (ch)
    {
    case 'A':
    case 'E':
    case 'I':
    case 'O':
    case 'U':
    case 'Y':
    case 'a':
    case 'e':
    case 'i':
    case 'o':
    case 'u':
    case 'y':
        return true;
    default:
        return false;
    }
}

string rotate(string str)
{
    string::size_type len = str.length();

    string str1;

    str1 = str.substr(1, len - 1) + str[0];

    return str1;
}

string plString(string str)
{
    string::size_type len;

    bool Vowel;

    string::size_type counter;

    if (isVowel(str[0]))                       //Step 1
        str = str + "-yay";
    else                                        //Step 2
    {
        str = str + '-';
        str = rotate(str);                    //Step 3

        len = str.length();                    //Step 3.a
        Vowel = false;                     //Step 3.b

        for (counter = 1; counter < len - 1;
                          counter++)            //Step 3.d
            if (isVowel(str[0]))
            {
               Vowel = true;
                break;
            }
            else                                //Step 3.c
                str = rotate(str);

        if (!Vowel)                        //Step 4
            str = str.substr(1, len) + "-way";
        else
            str = str + "ay";
    }

    return str;                                //Step 5
}
Topic archived. No new replies allowed.