Help fixing error in code

I keep getting an error, have not had success fixing. Error says:

assignment8b4.cpp:34:18: error: unknown type name 'ch'

bool isVowel(ch)//checking whether vowel or nor
^
assignment8b4.cpp:36:13: error: use of undeclared identifier 'ch'
switch (ch)//switch statement

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
#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
    }

    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(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;
    }
Compare lines 6
 
bool isVowel(char ch);

and 33
 
bool isVowel(ch)


At line 33 the type of the parameter ch has been omitted. It should read char ch, same as at line 6.
@Chervil Ok I am getting a new warning now:

assignment8b4.cpp:63:5: warning: control reaches end of non-void function
[-Wreturn-type]
}
^
Last edited on
Your function string rotate(string pStr) needs to return something. You forgot return rStr; at the end of that function.
ok i added the return rStr and i am still getting an error message:


[code]
// Reid Radebaugh- This program converts a string to pig latin
#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;
}
[code]
Last edited on
Topic archived. No new replies allowed.