6 Replies - 1514 Views - Last Post: 29 October 2006 - 06:50 AM Rate Topic: -----

#1 aznballerlee  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 61
  • Joined: 14-October 06

Boolean Expression

Posted 26 October 2006 - 05:53 PM

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.



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?

Is This A Good Question/Topic? 0
  • +

Replies To: Boolean Expression

#2 NyeNye  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 248
  • Joined: 24-September 06

Re: Boolean Expression

Posted 26 October 2006 - 06:01 PM

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

how bout trying a switch statement for each directions..
Was This Post Helpful? 0
  • +
  • -

#3 aznballerlee  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 61
  • Joined: 14-October 06

Re: Boolean Expression

Posted 26 October 2006 - 07:15 PM

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


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??
Was This Post Helpful? 0
  • +
  • -

#4 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: Boolean Expression

Posted 26 October 2006 - 07:23 PM

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.
Was This Post Helpful? 0
  • +
  • -

#5 aznballerlee  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 61
  • Joined: 14-October 06

Re: Boolean Expression

Posted 27 October 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?




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;
	 }
	}
}



Was This Post Helpful? 0
  • +
  • -

#6 gregoryH  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 60
  • View blog
  • Posts: 656
  • Joined: 04-October 06

Re: Boolean Expression

Posted 29 October 2006 - 01:22 AM

View Postaznballerlee, on 27 Oct, 2006 - 01:46 PM, said:

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:

/*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:
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 October 2006 - 06:56 AM

Was This Post Helpful? 0
  • +
  • -

#7 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,506
  • Joined: 12-July 02

Re: Boolean Expression

Posted 29 October 2006 - 06:50 AM

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:
case 'd':


is valid, while
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.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1