473,322 Members | 1,510 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,322 software developers and data experts.

Having trouble with a recursion program - Wff 'n Proof

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
1 2115
Anyone have any ideas at all? : ) I'm dyin' over here.
Jan 21 '07 #2

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

Similar topics

43
by: Lorenzo Villari | last post by:
I've tried to transform this into a not recursive version but without luck... #include <stdio.h> void countdown(int p) { int x;
10
by: paulw | last post by:
Hi Please give problems that "HAS TO" to use recursion (recursive calls to itself.) Preferrably real world examples, not knights tour. I'm thinking about eliminating the use of stack... ...
5
by: Ioannis Vranos | last post by:
The following code is supposed to print all folder names of a folder but it does not work. Why? Change the folder in main() to a folder suitable for your system so as to test it. I created...
18
by: MTD | last post by:
Hello all, I've been messing about for fun creating a trial division factorizing function and I'm naturally interested in optimising it as much as possible. I've been told that iteration in...
9
by: Hemal | last post by:
Hi All, I need to know the memory required by a c program. Is there any tool/utility which can give me the memory usage in terms of DATA segment, TEXT segment, BSS segment etc. I am working...
5
by: Milan Krejci | last post by:
the thing is that descentant branches i dont want to expand do expand. $id variable contains an array of branches i want the program to go through (alcohol's id -beer id etc) function...
13
by: Mumia W. | last post by:
Hello all. I have a C++ program that can count the YOYOs that are in a grid of Y's and O's. For example, this Y O Y O O Y O Y O Y O O Y O Y Y O Y O Y O O Y O O Y Y O Y O
15
by: Gigs_ | last post by:
Can someone explain me this if l == : return else: return f(l) + l # <= cant figure this, how is all sum at the end? thanks!
35
by: Muzammil | last post by:
int harmonic(int n) { if (n=1) { return 1; } else { return harmonic(n-1)+1/n; } } can any help me ??
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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...
1
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: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.