473,249 Members | 1,783 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,249 software developers and data experts.

Something wrong with the "if" statement

compman9902
105 100+
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
13 1535
DeMan
1,806 1GB
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
105 100+
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
105 100+
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
1,806 1GB
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
niskin
109 100+
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
1,806 1GB
also, what niskin said
Jun 28 '07 #7
compman9902
105 100+
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
1,806 1GB
an "or" operator - one of these: ||
Jun 29 '07 #9
compman9902
105 100+
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
1,806 1GB
No Problemo
Jun 29 '07 #11
niskin
109 100+
What exactly is pig latin? Forgive me for my ignorance.
Jun 29 '07 #12
compman9902
105 100+
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
niskin
109 100+
Sounds good. Thanks.
Jun 30 '07 #14

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

Similar topics

9
by: LRW | last post by:
I'm not exactly sure how to even ask the question, and I know my terminology is not good as I'm a SQL beginner, but, here goes. I need to find a way to make an if statement within an array...or,...
3
by: Bartosz Wegrzyn | last post by:
I am trying to upload images using either exec command. The file is uploaded ok. My script: <html> <head> <title>Picture Upload Page</title> <?php if ($_POST=="upload") {
9
by: Scott Beavers | last post by:
I'm trying to create a form in Excel to sort from the form and take the data to another worksheet. I am very new to this and any help would be appreciated. I have a value in a cell that will...
1
by: M Wells | last post by:
Hi All, Just wondering if anyone can tell me if you can test for multiple conditions as part of an "IF" statement in T-SQL in SQL Server 2000? ie something like: IF @merr = 1 or @merr=2...
3
by: Mark Morton | last post by:
I'm writing an if statement for a UK credit card form validation script. Users who specify that their card is Switch need to enter either the issue number or the 'valid from' date. I'm trying to...
35
by: David Cleaver | last post by:
Hello all, I was wondering if there were some sort of limitations on the "if" statement? I'm writing a program which needs to check a bunch of conditions all at the same time (basically). And...
6
by: Jacob.Bruxer | last post by:
Hi, I'm pretty new to Visual Basic and programming in general. I want to know if it's possible to create an If statement that asks if a value is an integer. If it's an integer it does one thing,...
2
by: marsarden | last post by:
write code like: int main(void) { int a=10; if(a<20) {} } Compiler ok on dev-cpp . don't we have to add a ";" after if
2
by: ibukhari | last post by:
Hi, I have a question regarding a optimization in if statement in C. Which one is more optimised in the following. Is the assembly generated by compiler is differant for both cases? Is the machine...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.