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

Having trouble with a recursion program - Wff 'n Proof

P: 2
Hello everyone. I've been working on an assignment which is described here
[HTML]http://scidiv.bcc.ctc.edu/mg/211/programs/program5.htm[/HTML]
I've gotten to a point where it works for most cases but definitely has problems. My version allows for more than one total WFF, which isn't allowed. For instance, "pp" should not qualify, but it does in my version. Also, something like "ANp" isn't a wff, but would identify as so in my program. I've really gotten to the point where I'm just stuck in my own head at this point, unable to figure out how to do this. Well, here's my code. This was written using Visual C++ 2005, although that probably doesn't matter much. Also, we are allowed to use more arguments to the recursive function than just the string input. I'd really appreciate any suggestions.

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <string>
  3. #include <fstream>
  4.  
  5. using namespace std;
  6.  
  7. bool WFF(string);
  8.  
  9. int main()
  10. {
  11.     string input;
  12.     ofstream outData;
  13.  
  14.     outData.open("output.dat");
  15.  
  16.     cout << "Enter a string to test: ";
  17.     getline(cin, input);
  18.     while (! input.empty())
  19.     {
  20.         if (WFF(input))
  21.         {
  22.             cout << input << " is a WFF.\n";
  23.             outData << input << " is a WFF.\n"; 
  24.         }
  25.         else
  26.         {
  27.             cout << input << " is not a WFF.\n";
  28.             outData << input << " is not a WFF.\n"; 
  29.         }
  30.         cout << "Enter a string to test: ";
  31.         getline(cin, input);
  32.     } 
  33.     return 0;
  34.  
  35. }
  36.  
  37. bool WFF(string input)
  38. {
  39.     if ((input[0]=='p'||input[0]=='q'||input[0]=='r'||input[0]=='s')&&
  40.          input.length()==1)        
  41.         return true; 
  42.     if ((input[0]=='p'||input[0]=='q'||input[0]=='r'||input[0]=='s')&&
  43.          input.length()>1)        
  44.         return WFF(input.substr(1,input.length()-1));
  45.     if (input[0]=='N'&&input.length()>1)
  46.         return WFF(input.substr(1,input.length()-1));
  47.     if ((input[0]=='C'||input[0]=='A'||input[0]=='K'||input[0]=='E')&&
  48.          input.length()>2)        
  49.         return WFF(input.substr(1,input.length()-1));
  50.     else
  51.         return false;
  52. }
Jan 20 '07 #1
Share this Question
Share on Google+
1 Reply


P: 2
Anyone have any ideas at all? : ) I'm dyin' over here.
Jan 21 '07 #2

Post your reply

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