Welcome to Dream.In.Code
Become a C++ Expert!

Join 137,392 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,124 people online right now. Registration is fast and FREE... Join Now!




Boolean Expression

 
Reply to this topicStart new topic

Boolean Expression

aznballerlee
26 Oct, 2006 - 04:53 PM
Post #1

D.I.C Head
**

Joined: 14 Oct, 2006
Posts: 61


My Contributions
I want to say that if the character is either L, l, D, d, U, u, R, r, /, or a digit (0-9) then
the dance is well formed.

I got a start on that and this is what I have.


CODE


bool isDanceWellFormed (string dance)
{
    int beat;
    char direction= 'L', 'l', 'D', 'd', 'U', 'u', 'R', 'r';
    beat = '/' || char direction;
    int digit = input [i] - '0';
    if (
    



Can you help me out on how to do that?
User is offlineProfile CardPM
+Quote Post

NyeNye
RE: Boolean Expression
26 Oct, 2006 - 05:01 PM
Post #2

D.I.C Head
**

Joined: 24 Sep, 2006
Posts: 248


My Contributions
what methods you or procedure that you try for each hotkeys;

how bout trying a switch statement for each directions..
User is offlineProfile CardPM
+Quote Post

aznballerlee
RE: Boolean Expression
26 Oct, 2006 - 06:15 PM
Post #3

D.I.C Head
**

Joined: 14 Oct, 2006
Posts: 61


My Contributions
I don't know, but switch statements look like a lot.
I tried something like this:

CODE


bool isDanceWellFormed (string dance)
{
    int beat;
    char direction = 'L', 'l', 'D', 'd', 'U', 'u', 'R', 'r';
    int number = '0', '1', '2', '3', '4', '5', '6', '7', '8', '9';
    
    
    
    int i;
    for (i = 0, i = inputsize (); i++)
    int digit = input [i] - '0';
if (input [i] != '/'
|| input [i] != direction
|| input [i] != number) // checks to see if characters are /, number, or direction
    cerr << "Error" << endl;

    if ( (input [i] >= '0' && input [i] <= '9') || direction || '/' )
    cerr << "Error" << endl;    

    
    int i;
    for (i = 0, i = inputsize (); i++)
{
    if (input [i] >= '0' && input [i] <= '9')
    {
        int digit = input [i] - '0';
        if (j= i+1 && input [j]!= direction)
            cerr << "Error";          

        for (j= i+2; j< i+2 + digit - 1; j++)
        {
            if (input [j] != "/")
                cerr << "Error";
        }
    }
}



I'm trying to check that the string has characters that are either '/','a number', or a direction (D, R, U, L).

So anything wrong??
User is offlineProfile CardPM
+Quote Post

Amadeus
RE: Boolean Expression
26 Oct, 2006 - 06:23 PM
Post #4

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,230



Thanked: 40 times
Dream Kudos: 25
My Contributions
Yes...you are declaring a single char variable, and the trying to assign multiple values to it, separated by commas. This will not work. If you want an array of vaid characters, you will have to declare it as such, and then loop through the array to check against input.

You are also declaring a single integer variable, and then trying to assign multiple values to it...same problem. This one is further compounded by the fact that you are tring to assign the characters for the numbers instead of the actual numbers themselves.
User is offlineProfile CardPM
+Quote Post

aznballerlee
RE: Boolean Expression
27 Oct, 2006 - 12:46 PM
Post #5

D.I.C Head
**

Joined: 14 Oct, 2006
Posts: 61


My Contributions
Okay, I'm taking smaller steps. I'm only trying to test for beats now.

A beat is any one of the following:

* a slash (/)
* a direction followed by a slash
* a digit followed by a direction followed by a slash
* two digits followed by a direction followed by a slash

Is my code working? I know it isn't actially, but what can I fix?


CODE



1) Case 1: '/'

for (i = 0; i = inputsize (); i++)
{
if (input [i] != '/')
{
   cerr << "Error" << endl;
}

}

2) Case 2: 'd/'

for (i = 0; i = inputsize (); i++)
{
if (input [i] == direction

       for (j = i + 1; j+1; i++)
{

       {
         if (input [j] != '/')
         cerr << "Error" << endl;
       }
}
}

3) Case 3: '3r/'

int i;
for (i = 0; i = inputsize (); i++)
{
    if (input [i] >= '0' && input [i] <= '9')
    {
        for (j = i+1; j+1; i++)
        {
       if (input [j] != direction)
       {
        cerr << "Error" << endl;
       }
        if (input [j+1] != '/')
        {
        cerr << "Error" << endl;
        }
        }
    }
}

4) Case 4: '03d/'

int i;
for (i = 0; i = inputsize (); i++)
{
    if (input [i] >= '0' && input [i] <= '9')
    {
     if (input [i+2] != direction)
     {
     cerr << "Error" << endl;
     }
     if (input [i+3] != '/')
     {
     cerr << "Error" << endl;
     }
    }
}


User is offlineProfile CardPM
+Quote Post

gregoryH
RE: Boolean Expression
29 Oct, 2006 - 12:22 AM
Post #6

D.I.C Regular
Group Icon

Joined: 4 Oct, 2006
Posts: 417


Dream Kudos: 50
My Contributions
QUOTE(aznballerlee @ 27 Oct, 2006 - 01:46 PM) *

Okay, I'm taking smaller steps. I'm only trying to test for beats now.

A beat is any one of the following:

* a slash (/)
* a direction followed by a slash
* a digit followed by a direction followed by a slash
* two digits followed by a direction followed by a slash
Is my code working? I know it isn't actially, but what can I fix?


I am having a little problem with the code style, when you write 1) Case 1: '/' I am not sure if you have applied ( or tried to) comments or if its meant to look like that. If you wanted comments, then try this:

CODE

/*1)*/ Case 1: // '/'

for (i = 0; i = inputsize (); i++)
{
if (input [i] != '/')
{
   cerr << "Error" << endl;
}

}

/*2)*/ Case 2: // 'd/'


the switchstatement is all lower case, including the case part... you should code it like:
CODE
switch ( value )
{
  case 1 :
    dosomething();
    break; // this is how you ckip the rest of the case statements
  case 2:
   dosomethingelse();
   break;
//etc until
  default: // when something is wrong
}

}

This post has been edited by gregoryH: 29 Oct, 2006 - 05:56 AM
User is offlineProfile CardPM
+Quote Post

Amadeus
RE: Boolean Expression
29 Oct, 2006 - 05:50 AM
Post #7

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,230



Thanked: 40 times
Dream Kudos: 25
My Contributions
To further elaborate on GregoryH's excellent suggestions, it appears as if you are tring to evaluate a case statement...a case statement will evaluate on either integers or single characters. For example this:
CODE

case 'd':

is valid, while
CODE

case 'd/'

is not.

Given what you appear to me trying to do, it may be easier for you to have an array of valid characters, and then loop through that array to see if each member of the input is valid...meaning it exists in that array.

Question: are you using C, or C++? I only ask becasue if you are using C++, the string object may well be of some value here.
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/5/08 02:34AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month