By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,395 Members | 2,537 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,395 IT Pros & Developers. It's quick & easy.

Something wrong with the "if" statement

compman9902
100+
P: 105
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:
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. using namespace std;
  5. string platin(string original);
  6. int main()
  7. {
  8. string bub;
  9. do {
  10. cout << "Enter One Word: ";
  11. getline (cin, bub);
  12. cout << "\n\nOriginal : " << bub << endl;
  13. cout << "Pig Latin: " << platin(bub) << "\n\n" << endl;
  14. } while (bub != "exit");
  15. return 0;
  16. }
  17.  
  18. string platin(string original)
  19. {
  20. string a;
  21. string b;
  22. string c;
  23. string d;
  24. string e;
  25. string final;
  26. int positionOne = 0;
  27. int positionTwo = 0;
  28. int positionThree = 0;
  29. positionTwo = original.find(" ", positionThree);
  30. positionThree = positionTwo;
  31. a = original.substr(positionOne, (positionTwo - positionOne));
  32. b = a[0];
  33. c = a.substr(0, 2);
  34. d = a.substr(0, 3);
  35. if ((b == "a") || (b == "e") || (b == "i") || (b == "o") || (b == "u")) {
  36.          e = original + "yay";
  37. }
  38. else if (original == "nix") {
  39.          e = "ixnay";
  40. }
  41. else if (original == "scram") {
  42.          e = "amscray";
  43. }
  44. else if (original == "hour") {
  45.          e = "houray";
  46. }
  47. 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")) {
  48.          d = a.substr(2);
  49.          e = d + c + "ay";
  50. }
  51. 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") || ) {
  52.          c = a.substr(3);
  53.          e = c + d + "ay";
  54. }
  55. else {
  56.          c = a.substr(1);
  57.          e = c + b + "ay";
  58. }
  59. positionOne = positionTwo;
  60. final = final + e;
  61. return final;
  62. }
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
Jun 28 '07 #1
Share this Question
Share on Google+
13 Replies


DeMan
100+
P: 1,806
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:
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. using namespace std;
  5. string platin(string original);
  6. int main()
  7. {
  8. string bub;
  9. do {
  10. cout << "Enter One Word: ";
  11. getline (cin, bub);
  12. cout << "\n\nOriginal : " << bub << endl;
  13. cout << "Pig Latin: " << platin(bub) << "\n\n" << endl;
  14. } while (bub != "exit");
  15. return 0;
  16. }
  17.  
  18. string platin(string original)
  19. {
  20. string a;
  21. string b;
  22. string c;
  23. string d;
  24. string e;
  25. string final;
  26. int positionOne = 0;
  27. int positionTwo = 0;
  28. int positionThree = 0;
  29. positionTwo = original.find(" ", positionThree);
  30. positionThree = positionTwo;
  31. a = original.substr(positionOne, (positionTwo - positionOne));
  32. b = a[0];
  33. c = a.substr(0, 2);
  34. d = a.substr(0, 3);
  35. if ((b == "a") || (b == "e") || (b == "i") || (b == "o") || (b == "u")) {
  36.          e = original + "yay";
  37. }
  38. else if (original == "nix") {
  39.          e = "ixnay";
  40. }
  41. else if (original == "scram") {
  42.          e = "amscray";
  43. }
  44. else if (original == "hour") {
  45.          e = "houray";
  46. }
  47. 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")) {
  48.          d = a.substr(2);
  49.          e = d + c + "ay";
  50. }
  51. 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") || ) {
  52.          c = a.substr(3);
  53.          e = c + d + "ay";
  54. }
  55. else {
  56.          c = a.substr(1);
  57.          e = c + b + "ay";
  58. }
  59. positionOne = positionTwo;
  60. final = final + e;
  61. return final;
  62. }
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
Expand|Select|Wrap|Line Numbers
  1. 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") || ) {
  2.  
  3.  
(actually I added six, I hope that was all)
Jun 28 '07 #2

compman9902
100+
P: 105
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
Expand|Select|Wrap|Line Numbers
  1. 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") || ) {
  2.  
  3.  
(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.
Jun 28 '07 #3

compman9902
100+
P: 105
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:
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. using namespace std;
  5. string platin(string original);
  6. int main()
  7. {
  8. string bub;
  9. do {
  10. cout << "Enter One Word: ";
  11. getline (cin, bub);
  12. cout << "\n\nOriginal : " << bub << endl;
  13. cout << "Pig Latin: " << platin(bub) << "\n\n" << endl;
  14. } while (bub != "exit");
  15. return 0;
  16. }
  17.  
  18. string platin(string original)
  19. {
  20. string a;
  21. string b;
  22. string c;
  23. string d;
  24. string e;
  25. string final;
  26. int positionOne = 0;
  27. int positionTwo = 0;
  28. int positionThree = 0;
  29. positionTwo = original.find(" ", positionThree);
  30. positionThree = positionTwo;
  31. a = original.substr(positionOne, (positionTwo - positionOne));
  32. b = a[0];
  33. c = a.substr(0, 2);
  34. d = a.substr(0, 3);
  35. if ((b == "a") || (b == "e") || (b == "i") || (b == "o") || (b == "u")) {
  36.          e = original + "yay";
  37. }
  38. else if (original == "nix") {
  39.          e = "ixnay";
  40. }
  41. else if (original == "scram") {
  42.          e = "amscray";
  43. }
  44. else if (original == "hour") {
  45.          e = "houray";
  46. }
  47. 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")) {
  48.          d = a.substr(2);
  49.          e = d + c + "ay";
  50. }
  51. 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")) {
  52.          c = a.substr(3);
  53.          e = c + d + "ay";
  54. }
  55. else {
  56.          c = a.substr(1);
  57.          e = c + b + "ay";
  58. }
  59. positionOne = positionTwo;
  60. final = final + e;
  61. return final;
  62. }
Here is the compiler error I keep getting:
"std::operator== [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>](((const std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)((const std::basic_string<char, std::char_traits<char>, std::allocator<char> >*)(&c))), ((const char*)"hh"))' cannot be used as a function"
This is for line 47.
Thank you.
Jun 28 '07 #4

DeMan
100+
P: 1,806
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
Expand|Select|Wrap|Line Numbers
  1.  
  2. 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")) {
  3. }
Jun 28 '07 #5

100+
P: 109
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.
Jun 28 '07 #6

DeMan
100+
P: 1,806
also, what niskin said
Jun 28 '07 #7

compman9902
100+
P: 105
Sorry Parker (It was late and I glanced at your name, my bad!!)
Line 47 also has a missing or
Expand|Select|Wrap|Line Numbers
  1.  
  2. 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")) {
  3. }
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 .
Jun 29 '07 #8

DeMan
100+
P: 1,806
an "or" operator - one of these: ||
Jun 29 '07 #9

compman9902
100+
P: 105
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 ;).
Jun 29 '07 #10

DeMan
100+
P: 1,806
No Problemo
Jun 29 '07 #11

100+
P: 109
What exactly is pig latin? Forgive me for my ignorance.
Jun 29 '07 #12

compman9902
100+
P: 105
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.
Jun 30 '07 #13

100+
P: 109
Sounds good. Thanks.
Jun 30 '07 #14

Post your reply

Sign in to post your reply or Sign up for a free account.