Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Pig-Latin Translator

Pig-Latin Translator

Scheduled Pinned Locked Moved C / C++ / MFC
help
8 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    arsenalgunners01
    wrote on last edited by
    #1

    I have been working on this for a couple of days. I am having trouble understanding why my program seems to hang after the input is translated. From what I can see the program never leaves the while loop. I must clarify that I still am a newbie so forgive me for my stupidity. Any help will be greatly appreciated. Here is what I have so far: #include #include #include class translate { private: char english[20]; public: translate(); }; int main() { translate sentence; return 0; } translate::translate() { char ans; do { cout<<"Please enter a sentence:\n"; while(cin>>english) { if((english[0] == 'a') || (english[0] == 'a') || (english[0] == 'A') || (english[0] == 'e') || (english[0] == 'E') || (english[0] == 'i') || (english[0] == 'I') || (english[0] == 'o') || (english[0] == 'O') || (english[0] == 'u') || (english[0] == 'U')) { cout<> ans; } while((ans == 'y') || (ans == 'Y')); return; }

    N N A M 4 Replies Last reply
    0
    • A arsenalgunners01

      I have been working on this for a couple of days. I am having trouble understanding why my program seems to hang after the input is translated. From what I can see the program never leaves the while loop. I must clarify that I still am a newbie so forgive me for my stupidity. Any help will be greatly appreciated. Here is what I have so far: #include #include #include class translate { private: char english[20]; public: translate(); }; int main() { translate sentence; return 0; } translate::translate() { char ans; do { cout<<"Please enter a sentence:\n"; while(cin>>english) { if((english[0] == 'a') || (english[0] == 'a') || (english[0] == 'A') || (english[0] == 'e') || (english[0] == 'E') || (english[0] == 'i') || (english[0] == 'I') || (english[0] == 'o') || (english[0] == 'O') || (english[0] == 'u') || (english[0] == 'U')) { cout<> ans; } while((ans == 'y') || (ans == 'Y')); return; }

      N Offline
      N Offline
      Nick Parker
      wrote on last edited by
      #2

      Constructors are for initializing member variables of a class instance, you should place the application specific code within a function that you call after construction, not during. Ex:

      class translate
      {
      public:
      translate(){}
      int Process();
      };

      int translate::Process()
      {
      // application code here...
      }


      Nick Parker

      The only man who never makes a mistake is the man who never does anything. - Theodore Roosevelt

      1 Reply Last reply
      0
      • A arsenalgunners01

        I have been working on this for a couple of days. I am having trouble understanding why my program seems to hang after the input is translated. From what I can see the program never leaves the while loop. I must clarify that I still am a newbie so forgive me for my stupidity. Any help will be greatly appreciated. Here is what I have so far: #include #include #include class translate { private: char english[20]; public: translate(); }; int main() { translate sentence; return 0; } translate::translate() { char ans; do { cout<<"Please enter a sentence:\n"; while(cin>>english) { if((english[0] == 'a') || (english[0] == 'a') || (english[0] == 'A') || (english[0] == 'e') || (english[0] == 'E') || (english[0] == 'i') || (english[0] == 'I') || (english[0] == 'o') || (english[0] == 'O') || (english[0] == 'u') || (english[0] == 'U')) { cout<> ans; } while((ans == 'y') || (ans == 'Y')); return; }

        N Offline
        N Offline
        Nitron
        wrote on last edited by
        #3

        arsenalgunners01 wrote: Pig-Latin Translator :wtf: And I thought I was up too late... ;P - Nitron


        "Those that say a task is impossible shouldn't interrupt the ones who are doing it." - Chinese Proverb

        1 Reply Last reply
        0
        • A arsenalgunners01

          I have been working on this for a couple of days. I am having trouble understanding why my program seems to hang after the input is translated. From what I can see the program never leaves the while loop. I must clarify that I still am a newbie so forgive me for my stupidity. Any help will be greatly appreciated. Here is what I have so far: #include #include #include class translate { private: char english[20]; public: translate(); }; int main() { translate sentence; return 0; } translate::translate() { char ans; do { cout<<"Please enter a sentence:\n"; while(cin>>english) { if((english[0] == 'a') || (english[0] == 'a') || (english[0] == 'A') || (english[0] == 'e') || (english[0] == 'E') || (english[0] == 'i') || (english[0] == 'I') || (english[0] == 'o') || (english[0] == 'O') || (english[0] == 'u') || (english[0] == 'U')) { cout<> ans; } while((ans == 'y') || (ans == 'Y')); return; }

          A Offline
          A Offline
          arsenalgunners01
          wrote on last edited by
          #4

          Thanks for the advice, but that doesn't solve my problem.

          T 1 Reply Last reply
          0
          • A arsenalgunners01

            Thanks for the advice, but that doesn't solve my problem.

            T Offline
            T Offline
            trustno1
            wrote on last edited by
            #5

            without looking @ your code in depth.. i can suggest you a ways to solve your infinite loop problem.. instead of using while(cin>english), you can use the length of the string of the input as your while conditional variable.. every loop, you minus the conditional variable by 1.. by the time the conditional variable reach 0(meaning you have finished check every letter), your program will exit the loop for sure..

            A 1 Reply Last reply
            0
            • A arsenalgunners01

              I have been working on this for a couple of days. I am having trouble understanding why my program seems to hang after the input is translated. From what I can see the program never leaves the while loop. I must clarify that I still am a newbie so forgive me for my stupidity. Any help will be greatly appreciated. Here is what I have so far: #include #include #include class translate { private: char english[20]; public: translate(); }; int main() { translate sentence; return 0; } translate::translate() { char ans; do { cout<<"Please enter a sentence:\n"; while(cin>>english) { if((english[0] == 'a') || (english[0] == 'a') || (english[0] == 'A') || (english[0] == 'e') || (english[0] == 'E') || (english[0] == 'i') || (english[0] == 'I') || (english[0] == 'o') || (english[0] == 'O') || (english[0] == 'u') || (english[0] == 'U')) { cout<> ans; } while((ans == 'y') || (ans == 'Y')); return; }

              M Offline
              M Offline
              Michael P Butler
              wrote on last edited by
              #6

              while(cin>>english) Remove this while loop and just do cin>>english as this is causing an infinite loop and not getting to your cout<<"Would you like to have another sentence translated,?\n"; cout<<"Type [Y] for yes and [N] for no:\n"; code. Michael The avalanche has started, it's too late for the pebbles to vote.

              1 Reply Last reply
              0
              • T trustno1

                without looking @ your code in depth.. i can suggest you a ways to solve your infinite loop problem.. instead of using while(cin>english), you can use the length of the string of the input as your while conditional variable.. every loop, you minus the conditional variable by 1.. by the time the conditional variable reach 0(meaning you have finished check every letter), your program will exit the loop for sure..

                A Offline
                A Offline
                arsenalgunners01
                wrote on last edited by
                #7

                How can I get the length of the string if it hasn't even been inputed by that point?

                T 1 Reply Last reply
                0
                • A arsenalgunners01

                  How can I get the length of the string if it hasn't even been inputed by that point?

                  T Offline
                  T Offline
                  trustno1
                  wrote on last edited by
                  #8

                  well, you get the input first, then get the length of the string.. once you done all that, you do your while loop.. lemme give you pseudo codes here: let x, y be variables x = input string from the user y = string length of x while(y) { ...do your pig latin thing... y = y -1 }

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups