Something wrong with the "if" statement

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • compman9902
    New Member
    • Mar 2007
    • 105

    Something wrong with the "if" statement

    Hello, and thank you for hwlping me with this run-in with trouble.
    I am making a script for pig latin transulation, and there is something wrong with the "if" statement in line 51. Here is the code so far:
    Code:
    #include <iostream>
    #include <stdlib.h>
    #include <string.h>
    using namespace std;
    string platin(string original);
    int main()
    {
    string bub;
    do {
    cout << "Enter One Word: ";
    getline (cin, bub);
    cout << "\n\nOriginal : " << bub << endl;
    cout << "Pig Latin: " << platin(bub) << "\n\n" << endl;
    } while (bub != "exit");
    return 0;
    }
    
    string platin(string original)
    {
    string a;
    string b;
    string c;
    string d;
    string e;
    string final;
    int positionOne = 0;
    int positionTwo = 0;
    int positionThree = 0;
    positionTwo = original.find(" ", positionThree);
    positionThree = positionTwo;
    a = original.substr(positionOne, (positionTwo - positionOne));
    b = a[0];
    c = a.substr(0, 2);
    d = a.substr(0, 3);
    if ((b == "a") || (b == "e") || (b == "i") || (b == "o") || (b == "u")) {
    		 e = original + "yay";
    }
    else if (original == "nix") {
    		 e = "ixnay";
    }
    else if (original == "scram") {
    		 e = "amscray";
    }
    else if (original == "hour") {
    		 e = "houray";
    }
    else if ((c == "aa") || (c == "ae") || (c == "ah") || (c == "ao") || (c == "aw") || (c == "ax") || (c == "ay") || (c == "ea") || (c == "eh") || (c == "er") || (c == "ey") || (c == "ia") || (c == "ih") || (c == "iy") || (c == "oh") || (c == "ow") || (c == "oy") || (c == "ua") || (c == "uh") || (c == "uw") || (c == "th") || (c == "dh") || (c == "sh") || (c == "zh") || (c == "ch") || (c == "jh") || (c == "ng") || (c == "hh") (c == "ph") || (c == "qu")) {
    		 d = a.substr(2);
    		 e = d + c + "ay";
    }
    else if ((d == b + "aa") || (d == b + "ae") || (d == b + "ah") || (d == b + "ao") (d == b + "aw") || (d == b + "ax") || (d == b + "ay") || (d == b + "ea") || (d == b + "eh") (d == b + "er") || (d == b + "ey") || (d == b + "ia") || (d == b + "ih") || (d == b + "iy") (d == b + "oh") || (d == b + "ow") || (d == b + "oy") || (d == b + "ua") || (d == b + "uh") (d == b + "uw") || (d == b + "th") || (d == b + "dh") || (d == b + "sh") || (d == b + "zh") (d == b + "ch") || (d == b + "jh") || (d == b + "ng") || (d == b + "hh") || (d == b + "ph") (d == b + "qu") || ) {
    		 c = a.substr(3);
    		 e = c + d + "ay";
    }
    else {
    		 c = a.substr(1);
    		 e = c + b + "ay";
    }
    positionOne = positionTwo;
    final = final + e;
    return final;
    }
    Please post code when you reply to this post. Thank you.
    By the way, here are my compiler/envirnment specs.:
    Envirnment : Dev-C++ 4.9.9.2
    Compiler : GCC.exe
  • DeMan
    Top Contributor
    • Nov 2006
    • 1799

    #2
    Originally posted by compman9902
    Hello, and thank you for hwlping me with this run-in with trouble.
    I am making a script for pig latin transulation, and there is something wrong with the "if" statement in line 51. Here is the code so far:
    Code:
    #include <iostream>
    #include <stdlib.h>
    #include <string.h>
    using namespace std;
    string platin(string original);
    int main()
    {
    string bub;
    do {
    cout << "Enter One Word: ";
    getline (cin, bub);
    cout << "\n\nOriginal : " << bub << endl;
    cout << "Pig Latin: " << platin(bub) << "\n\n" << endl;
    } while (bub != "exit");
    return 0;
    }
    
    string platin(string original)
    {
    string a;
    string b;
    string c;
    string d;
    string e;
    string final;
    int positionOne = 0;
    int positionTwo = 0;
    int positionThree = 0;
    positionTwo = original.find(" ", positionThree);
    positionThree = positionTwo;
    a = original.substr(positionOne, (positionTwo - positionOne));
    b = a[0];
    c = a.substr(0, 2);
    d = a.substr(0, 3);
    if ((b == "a") || (b == "e") || (b == "i") || (b == "o") || (b == "u")) {
    		 e = original + "yay";
    }
    else if (original == "nix") {
    		 e = "ixnay";
    }
    else if (original == "scram") {
    		 e = "amscray";
    }
    else if (original == "hour") {
    		 e = "houray";
    }
    else if ((c == "aa") || (c == "ae") || (c == "ah") || (c == "ao") || (c == "aw") || (c == "ax") || (c == "ay") || (c == "ea") || (c == "eh") || (c == "er") || (c == "ey") || (c == "ia") || (c == "ih") || (c == "iy") || (c == "oh") || (c == "ow") || (c == "oy") || (c == "ua") || (c == "uh") || (c == "uw") || (c == "th") || (c == "dh") || (c == "sh") || (c == "zh") || (c == "ch") || (c == "jh") || (c == "ng") || (c == "hh") (c == "ph") || (c == "qu")) {
    		 d = a.substr(2);
    		 e = d + c + "ay";
    }
    else if ((d == b + "aa") || (d == b + "ae") || (d == b + "ah") || (d == b + "ao") (d == b + "aw") || (d == b + "ax") || (d == b + "ay") || (d == b + "ea") || (d == b + "eh") (d == b + "er") || (d == b + "ey") || (d == b + "ia") || (d == b + "ih") || (d == b + "iy") (d == b + "oh") || (d == b + "ow") || (d == b + "oy") || (d == b + "ua") || (d == b + "uh") (d == b + "uw") || (d == b + "th") || (d == b + "dh") || (d == b + "sh") || (d == b + "zh") (d == b + "ch") || (d == b + "jh") || (d == b + "ng") || (d == b + "hh") || (d == b + "ph") (d == b + "qu") || ) {
    		 c = a.substr(3);
    		 e = c + d + "ay";
    }
    else {
    		 c = a.substr(1);
    		 e = c + b + "ay";
    }
    positionOne = positionTwo;
    final = final + e;
    return final;
    }
    Please post code when you reply to this post. Thank you.
    By the way, here are my compiler/envirnment specs.:
    Envirnment : Dev-C++ 4.9.9.2
    Compiler : GCC.exe
    Hi Peter,

    What is th eproblem with the if. Is it not compiling, or is it misbehaving....
    Is it going to else when it shouldn't or is it going into the if when it shouldn't.

    You are missing at least three sets of or signs.....try
    [code=cpp]
    else if ((d == b + "aa") || (d == b + "ae") || (d == b + "ah") || (d == b + "ao") ||(d == b + "aw") || (d == b + "ax") || (d == b + "ay") || (d == b + "ea") || (d == b + "eh") ||(d == b + "er") || (d == b + "ey") || (d == b + "ia") || (d == b + "ih") || (d == b + "iy") ||(d == b + "oh") || (d == b + "ow") || (d == b + "oy") || (d == b + "ua") || (d == b + "uh")|| (d == b + "uw") || (d == b + "th") || (d == b + "dh") || (d == b + "sh") || (d == b + "zh")|| (d == b + "ch") || (d == b + "jh") || (d == b + "ng") || (d == b + "hh") || (d == b + "ph") ||(d == b + "qu") || ) {

    [/code]
    (actually I added six, I hope that was all)

    Comment

    • compman9902
      New Member
      • Mar 2007
      • 105

      #3
      Originally posted by DeMan
      Hi Peter,

      What is th eproblem with the if. Is it not compiling, or is it misbehaving....
      Is it going to else when it shouldn't or is it going into the if when it shouldn't.

      You are missing at least three sets of or signs.....try
      [code=cpp]
      else if ((d == b + "aa") || (d == b + "ae") || (d == b + "ah") || (d == b + "ao") ||(d == b + "aw") || (d == b + "ax") || (d == b + "ay") || (d == b + "ea") || (d == b + "eh") ||(d == b + "er") || (d == b + "ey") || (d == b + "ia") || (d == b + "ih") || (d == b + "iy") ||(d == b + "oh") || (d == b + "ow") || (d == b + "oy") || (d == b + "ua") || (d == b + "uh")|| (d == b + "uw") || (d == b + "th") || (d == b + "dh") || (d == b + "sh") || (d == b + "zh")|| (d == b + "ch") || (d == b + "jh") || (d == b + "ng") || (d == b + "hh") || (d == b + "ph") ||(d == b + "qu") || ) {

      [/code]
      (actually I added six, I hope that was all)
      Well, that actually worked fantastically. I'm not quite sure what you did, but what ever it was, it worked. But, now the if statement on line 47 is having a new error. The debugger said:
      "expected primary-expression before ')' token"
      I cannot figure out how to solve this.
      As for before, and now (for that matter), it is/was a compiler error.
      And I'm not Peter...Its Parker.

      Comment

      • compman9902
        New Member
        • Mar 2007
        • 105

        #4
        Originally posted by compman9902
        Well, that actually worked fantastically. I'm not quite sure what you did, but what ever it was, it worked. But, now the if statement on line 47 is having a new error. The debugger said:
        "expected primary-expression before ')' token"
        I cannot figure out how to solve this.
        As for before, and now (for that matter), it is/was a compiler error.
        And I'm not Peter...Its Parker.
        Okay, there is an update.
        I'm having a compiler error.
        Here is the code I am now working with:
        [code=cpp]#include <iostream>
        #include <stdlib.h>
        #include <string.h>
        using namespace std;
        string platin(string original);
        int main()
        {
        string bub;
        do {
        cout << "Enter One Word: ";
        getline (cin, bub);
        cout << "\n\nOrigin al : " << bub << endl;
        cout << "Pig Latin: " << platin(bub) << "\n\n" << endl;
        } while (bub != "exit");
        return 0;
        }

        string platin(string original)
        {
        string a;
        string b;
        string c;
        string d;
        string e;
        string final;
        int positionOne = 0;
        int positionTwo = 0;
        int positionThree = 0;
        positionTwo = original.find(" ", positionThree);
        positionThree = positionTwo;
        a = original.substr (positionOne, (positionTwo - positionOne));
        b = a[0];
        c = a.substr(0, 2);
        d = a.substr(0, 3);
        if ((b == "a") || (b == "e") || (b == "i") || (b == "o") || (b == "u")) {
        e = original + "yay";
        }
        else if (original == "nix") {
        e = "ixnay";
        }
        else if (original == "scram") {
        e = "amscray";
        }
        else if (original == "hour") {
        e = "houray";
        }
        else if ((c == "aa") || (c == "ae") || (c == "ah") || (c == "ao") || (c == "aw") || (c == "ax") || (c == "ay") || (c == "ea") || (c == "eh") || (c == "er") || (c == "ey") || (c == "ia") || (c == "ih") || (c == "iy") || (c == "oh") || (c == "ow") || (c == "oy") || (c == "ua") || (c == "uh") || (c == "uw") || (c == "th") || (c == "dh") || (c == "sh") || (c == "zh") || (c == "ch") || (c == "jh") || (c == "ng") || (c == "hh") (c == "ph") || (c == "qu")) {
        d = a.substr(2);
        e = d + c + "ay";
        }
        else if ((d == b + "aa") || (d == b + "ae") || (d == b + "ah") || (d == b + "ao") || (d == b + "aw") || (d == b + "ax") || (d == b + "ay") || (d == b + "ea") || (d == b + "eh") || (d == b + "er") || (d == b + "ey") || (d == b + "ia") || (d == b + "ih") || (d == b + "iy") || (d == b + "oh") || (d == b + "ow") || (d == b + "oy") || (d == b + "ua") || (d == b + "uh") || (d == b + "uw") || (d == b + "th") || (d == b + "dh") || (d == b + "sh") || (d == b + "zh") || (d == b + "ch") || (d == b + "jh") || (d == b + "ng") || (d == b + "hh") || (d == b + "ph") || (d == b + "qu")) {
        c = a.substr(3);
        e = c + d + "ay";
        }
        else {
        c = a.substr(1);
        e = c + b + "ay";
        }
        positionOne = positionTwo;
        final = final + e;
        return final;
        }[/code]
        Here is the compiler error I keep getting:
        "std::operator= = [with _CharT = char, _Traits = std::char_trait s<char>, _Alloc = std::allocator< char>](((const std::basic_stri ng<char, std::char_trait s<char>, std::allocator< char> >&)((const std::basic_stri ng<char, std::char_trait s<char>, std::allocator< char> >*)(&c))), ((const char*)"hh"))' cannot be used as a function"
        This is for line 47.
        Thank you.

        Comment

        • DeMan
          Top Contributor
          • Nov 2006
          • 1799

          #5
          Originally posted by compman9902
          else if ((c == "aa") || (c == "ae") || (c == "ah") || (c == "ao") || (c == "aw") || (c == "ax") || (c == "ay") || (c == "ea") || (c == "eh") || (c == "er") || (c == "ey") || (c == "ia") || (c == "ih") || (c == "iy") || (c == "oh") || (c == "ow") || (c == "oy") || (c == "ua") || (c == "uh") || (c == "uw") || (c == "th") || (c == "dh") || (c == "sh") || (c == "zh") || (c == "ch") || (c == "jh") || (c == "ng") || (c == "hh") (c == "ph") || (c == "qu")) {

          }
          .
          Sorry Parker (It was late and I glanced at your name, my bad!!)
          Line 47 also has a missing or
          Code:
          else if ((c == "aa") || (c == "ae") || (c == "ah") || (c == "ao") || (c == "aw") || (c == "ax") || (c == "ay") || (c == "ea") || (c == "eh") || (c == "er") || (c == "ey") || (c == "ia") || (c == "ih") || (c == "iy") || (c == "oh") || (c == "ow") || (c == "oy") || (c == "ua") || (c == "uh") || (c == "uw") || (c == "th") || (c == "dh") || (c == "sh") || (c == "zh") || (c == "ch") || (c == "jh") || (c == "ng") || (c == "hh") ||(c == "ph") || (c == "qu")) {
          }

          Comment

          • niskin
            New Member
            • Apr 2007
            • 109

            #6
            Well I'm not sure what's wrong but you are missing an operator towards the end of the line. Ah but DeMan has just got in there first with a post before me.

            Comment

            • DeMan
              Top Contributor
              • Nov 2006
              • 1799

              #7
              also, what niskin said

              Comment

              • compman9902
                New Member
                • Mar 2007
                • 105

                #8
                Originally posted by DeMan
                Sorry Parker (It was late and I glanced at your name, my bad!!)
                Line 47 also has a missing or
                Code:
                else if ((c == "aa") || (c == "ae") || (c == "ah") || (c == "ao") || (c == "aw") || (c == "ax") || (c == "ay") || (c == "ea") || (c == "eh") || (c == "er") || (c == "ey") || (c == "ia") || (c == "ih") || (c == "iy") || (c == "oh") || (c == "ow") || (c == "oy") || (c == "ua") || (c == "uh") || (c == "uw") || (c == "th") || (c == "dh") || (c == "sh") || (c == "zh") || (c == "ch") || (c == "jh") || (c == "ng") || (c == "hh") ||(c == "ph") || (c == "qu")) {
                }
                It has a missing what??
                I'm trying my best to not copy the code that you give me, but to learn and make my own code from the examples that you guys set.
                And its fine about the name .

                Comment

                • DeMan
                  Top Contributor
                  • Nov 2006
                  • 1799

                  #9
                  an "or" operator - one of these: ||

                  Comment

                  • compman9902
                    New Member
                    • Mar 2007
                    • 105

                    #10
                    Originally posted by DeMan
                    an "or" operator - one of these: ||
                    OH!!!
                    Now that you point it out, it has become extremely clear.
                    And, it works perfectly.
                    Next Time, I'll proofread my work more throughly, thanks guys.
                    Oh, by the way, the function for pig latin is free to use by anybody who wants to use it, just give me credit ;).

                    Comment

                    • DeMan
                      Top Contributor
                      • Nov 2006
                      • 1799

                      #11
                      No Problemo

                      Comment

                      • niskin
                        New Member
                        • Apr 2007
                        • 109

                        #12
                        What exactly is pig latin? Forgive me for my ignorance.

                        Comment

                        • compman9902
                          New Member
                          • Mar 2007
                          • 105

                          #13
                          Originally posted by niskin
                          What exactly is pig latin? Forgive me for my ignorance.
                          No problem.
                          According to Wikipedia, Pig Latin was actually originally a made up language made up by inmates to fool guards. Now, it is mostly for use on playgrounds, becasue it has become common knolage and children find it fun. You should look it up.

                          Comment

                          • niskin
                            New Member
                            • Apr 2007
                            • 109

                            #14
                            Sounds good. Thanks.

                            Comment

                            Working...