473,382 Members | 1,389 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,382 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 1541
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.