cannot get code to compile. HELP

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


	#include<iostream>
    #include<string>
    #include<algorithm>
    using namespace std;

    bool isVowel(char ch);//method to check whether ch is vowel or not..
    //if yes returns true//other wise false
    /**
    * Removes the first character of the string, and places it at the
    * end of the string.
    * @param pString the word to be rotated.
    * @return the new reordered string
    */
    string rotate(string pStr);
    // Introduces pigLatinString
    string pigLatinString(string pStr);
    int main()
    {
    string str;
    cout << "Enter a word: ";//prompting user to enter a word
    if (cin.peek() == '\n') //returns the next character in the input sequence
   {
    cin.ignore(1, '\n');//if it is line then ignoring it
	
	}
	return rStr;
    getline(cin, str);//reading line and storing in str
    cout << endl;
    // Output the text as pig Latin
    cout << "The pig Latin form of " << str << " is: "
    << pigLatinString(str) << endl;//printing output
    return 0;
    }
    bool isVowel(char ch)//checking whether vowel or nor
    {
    switch (ch)//switch statement
    {
		//for each vowel,upper and lower...defining cases to perform actions
    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;//after all cases this will execute
    default:
    return false;
    }
    }
    string rotate(string pStr)
    {
    string::size_type len = pStr.length();//finding string length
    string rStr;//new variable declaration
    rStr = pStr.substr(1, len - 1) + pStr[0];
		/*removing first character from pstr,and adding at the end,
		and assigned to rstr return rStr;//returning rotated string*/
    }
    string pigLatinString(string pStr)
    {
    string::size_type len;//variable declaration
    bool foundVowel;
    string::size_type counter;
    if (isVowel(pStr[0]))//if first char in pStr is vowel then
    pStr = pStr + "-way";//adding -way to pStr
    else//if it is not vowel
    {
    pStr = pStr + '-';//then adding - , at end of pStr
    pStr = rotate(pStr);//rotating pStr
    len = pStr.length();//finding length of new pStr
    foundVowel = false;
	for (counter = 1; counter < len - 1; counter++)
    {
    if (isVowel(pStr[0]))//checking first char in pstr is vowel or not
    {
    foundVowel = true;//if vowel
    break;
    }
    else
    pStr = rotate(pStr);     //rotating
    }
    if (!foundVowel)
    pStr = pStr.substr(1, len) + "-way";
    else  //if it is vowel
    pStr = pStr + "ay";
    }
    return pStr;
    }
Last edited on
int main()
{
string str;
cout << "Enter a word: ";//prompting user to enter a word
if (cin.peek() == '\n') //returns the next character in the input sequence
{
cin.ignore(1, '\n');//if it is line then ignoring it

}
return rStr;
^^^^^^^^^^^^^^^^^^
rStr does not exist.


you define it later, but the compiler does not care. You used it here, it has not seen it yet, so it does not exist yet, so this isn't allowed.
Last edited on
Topic archived. No new replies allowed.