Im getting this error while im working on my pig latin code and have no idea what it is referring too. so here is the error and my code.

ill specify the piece of code that is erroring.

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

bool isVowel(char ch);
string rotate(string pStr);
string pigLatinString(string pStr);


int main()
{
ifstream infile;
string newstr;
int length;
char achar;
string str; 
string str1;
string str2;
string str3;
string pStr;
char ch;

infile.open("C:\\201\\PigLatin.txt");

if(infile.is_open() == false)
{
    std::cerr << "Error, unable to open file." << std::endl;
    return 1;
}

std::string word;
while(infile.fail() == false)
{
    infile >> word;
    std::cout << pigLatinString(word) << ' ';
}

cout << endl;
cout << "Pig Latin String Is: " << endl;
cout << endl;
while (!infile.eof())
{
infile.get(achar);

if (achar != ' ') 
{
str = str + achar;

}	
else 
{
cout << pigLatinString(str)<< " ";
str = "";
}
}
if (achar == '!')
{
length = static_cast<unsigned int>(str.length());
newstr = str.substr(0,(length-2));
cout << " " << pigLatinString(newstr) << "!";
}
if (achar == '?')
{
length = static_cast<unsigned int>(str.length());
newstr = str.substr(0,(length-2));
cout << " " << pigLatinString(newstr) << "?";
}
if (achar == '.')
{
length = static_cast<unsigned int>(str.length());
newstr = str.substr(0,(length-2));
cout << " " << pigLatinString(newstr) << ".";
}

cout << endl;
str = "";
cout << endl;
isVowel(ch);
rotate (pStr);
pigLatinString(pStr);
infile.close();


return 0;
}

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

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

string rStr;

rStr = pStr.substr(1, len - 1) + pStr[0];

return rStr;
}

string pigLatinString(string pStr)
{
string::size_type len;

bool foundVowel;

string::size_type counter;

if (isVowel(pStr[0]))
pStr = pStr + "-way";
else
{
pStr = pStr + '-';
pStr = rotate(pStr);
len = pStr.length();
foundVowel = false;

for (counter = 1; counter < len - 1; counter++)
if (isVowel(pStr[0]))
{
foundVowel = true;
break;
}
else 
pStr = rotate(pStr);

if (!foundVowel)
pStr = pStr.substr(1,len) + "-way";
else
pStr = pStr + "ay";
}
return pStr;
}

here is the error i get:
1>c:\users\goncalvesa2\documents\visual studio 2010\projects\lab4problem1\lab4problem1\lab4problem1.cpp(88): error C2447: '{' : missing function header (old-style formal list?)

here is the piece of code it is referring too:

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

It is giving me an error message on the first '{' of the switch statement.
any help is appreciated.

Recommended Answers

All 4 Replies

make sure your braces match up. { }

Line 9 (second listing) should not look like that. Are you trying to call the function? It looks like a definition. Also, formatting your code with proper indentation would make it easier to spot errors with the braces. Lines 88-100 on the first listing seem like they are floating outside of any function.

right so should that switch statement be in a different function? and if so which one?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.