Hello, im a new C++ programmer. One of my first programs is to turn a normal english word into pig latin. I have one last error to sort out. I keep getting a parse error and i can't figure out why. the error is:
In function `int main()':
parse error before `['
confused by earlier errors, bailing out

the code is

#include <iostream.h>
#include <string.h>
#include <stdlib.h>
const int wordsize = 25;
const int tempsize = 5;
int main()
{
      cout << "input a word to be turned into pig latin";
      char word[wordsize];
      char vowels[6] = {'a','e','i','o','u','y'};
      char temp[tempsize];
      int i, q = 0 ;
      cin >> word;

      int p, k;
      char r;
      for (k = 25; r == '\0'; k--)
      {
      r == word[k];
      p = k;
      }

      char pig[p + 2];
      for (int f = 0; f == p; f++)
      {
      pig[f] = word[f];
      }

      for (i = 0; q == 1; i++)
      for (int x = 0; x == 6; x++)
      if word[i] == vowels[x]
      q = 1

      for (k = 0; k == i; k++)
      temp[k] = word[k];

      for (k = 0; k == p + 1; k++)
      {
      pig[k] = word[k + i];
      p = k;
      }
      int o = p + 1;
      for (k = 0; k == i; k++)
      pig[k + o] = temp[k];

      pig[0 + i + 1] = 'a';
      pig[0 + i + 2] = 'y' ;

      cout << pig;

      cout << '\n';
      system("PAUSE");
      return 0;
}

the indicated line (31) is in pink
I know its kind of messy but bear with me
please help

Recommended Answers

All 5 Replies

Some points to be noted:

1. Don't use the old style of header inclusion ( #include <iostream.h> ).
Instead use #include <iostream> followed by using namespace std ; .
The latest C++ standard has the concept of namespaces and aall the standard C++ functions in current compiler implementations are enclosed in the namespace std.

2.

for (k = 25; r == '\0'; k--)
{
     r == word[k];  // I guess you wanted to do assignment ?
     p = k;
}

3.

// you can't do this, it is not allowed in C / C++.
// The variable which specifies the dimension must be const qualified
// or must be defined using a Macro.
char pig[p + 2]; 

for (int f = 0; f == p; f++)
    pig[f] = word[f];

And so many more syntax errors like missing semicolons and what not. Try to eliminate the above mentioned along with the other simple errrors and then repost.

error message(same stuff, different line):
In function `int main()':
parse error before `['
confused by earlier errors, bailing out

Here is the edited code with the errors and a useless section taken out

#include <iostream>
#include <string>
#include <stdlib.h>
using namespace std;
const int wordsize = 25;
const int tempsize = 5;
int main()
{
      cout << "input a word to be turned into pig latin";
      //defining variables
      char word[wordsize];
      char vowels[6] = {'a','e','i','o','u','y'};
      char temp[tempsize];
      int i, p, k, q = 0 ;
      cin >> word;
      char r;

      //finding the number of letters
      for (k = 25; r == '\0'; k--)
      {
      r = word[k];
      p = k;
      }
      const int h = p;
      char pig[h + 2];

      //identifying constanants to be taken away
      for (i = 0; q == 1; i++)
      for (int x = 0; x == 6; x++)
      if word[i] == vowels[x]
      q = 1

      //adding constanants to temp
      for (k = 0; k == i; k++)
      temp[k] = word[k];

      //moving letters back in space of constanants
      for (k = 0; k == p + 1; k++)
      {
      pig[k] = word[k + i];
      p = k;
      }

      //adding constanants to the end
      int o = p + 1;
      for (k = 0; k == i; k++)
      pig[k + o] = temp[k];

      //add ay to the end
      pig[0 + i + 1] = 'a';
      pig[0 + i + 2] = 'y';

      //display final product
      cout << pig;

      cout << '\n';
      system("PAUSE");
      return 0;
}

code indicated in error is in pink

Don't know if you noticed, but those 2 lines are missing semicolons:

// added semicolons and brackets ;)
      if (word[i] == vowels[x]) ;
      q = 1;

that does not solve the error, but thanks anyway. and i don't believe the first semicolon is supposed to be there. from what i've read, you don't seperate the if statement from the action performed to be performed

that does not solve the error, but thanks anyway. and i don't believe the first semicolon is supposed to be there. from what i've read, you don't seperate the if statement from the action performed to be performed

Ah yes you are correct. I apologize for the mistake. I blindly added 2 semicolons, then realized that it was an if() statement, added brackets and forgot to remove the semicolon. Sorry about that.

If you add a semicolon to the second statement and make sure there's brackets around the if statement, it should work (at least compile). There's probably some bugs present, though.

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.