LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 12-05-2004, 10:08 PM   #1
illiniguy3043
Member
 
Registered: May 2004
Location: Illinois
Distribution: Ubuntu 8.04
Posts: 56

Rep: Reputation: 15
C syntax problem with if statements


I keep getting this pesky error "project.c", line 427: error: expected a ")" I searched all over and found no opening parentheses so I have no idea what this is coming from. Most likely I just made some stupid formatting error but I've checked out some C references and they seem to be consistent with what I did. I also get this error on several other lines as well as "project.c", line 433: error: expected an expression. Here's my code starting with line 391. Any assistance would be greatly appreciated.



if (flag1==1)
{
if (flag2==1)
{
if (flag4==1)
{
if (flag5==1)
{
//##################For Loops##########################
for(i=0;i<cnt1;i++)
{
sum1 = sum1 + vel1[i];
averagevel1 = sum1 / cnt1;
}

for(j=0;j<cnt2;j++)
{
sum2 = sum2 + vel2[j];
averagevel2 = sum2 / cnt2;
}

for(k=0;k<cnt4;k++)
{
sum4 = sum4 + vel4[k];
averagevel4 = sum4 / cnt4;
}

for(l=0;l<cnt5;l++)
{
sum5 = sum5 + vel5[l];
averagevel5 = sum5 / cnt5;
}
//#####################################################

frontratio = averagevel1/averagevel4;

if (frontratio > steerlimit)
{
slipratio = averagevel2/averagevel1;

if (slipratio > maxslip)
{
torque = (1 - (slipratio - maxslip))*maxtorque;
//******Put in serial_printf statement*******
}
else if (slipratio > threshhold)
{
torque = 0;
}
else torque = 1;

}

else if(frontratio < 1/steerlimit)
{
slipratio = averagevel5 / averagevel4;

if (slipratio > maxslip)
{
torque = (1 - (slipratio - maxslip))*maxtorque;
//******Put in serial_printf statement*******
}
else if (slipratio > threshhold)
{
torque = 0;
}
else torque = 1;
}

else
{
slipratio = (averagevel1 + averagevel4) / (averagevel5 + averagevel2);
if (slipratio > maxslip)
{
torque = (1 - (slipratio - maxslip))*maxtorque;
//******Put in serial_printf statement*******
}
else if (slipratio > threshhold)
{
torque = 0;
}
else torque = 1;

}

}//####### This is for flag5
}//######## This is for flag4
}//######## This is for flag2
}//####### This is for flag1
 
Old 12-05-2004, 10:15 PM   #2
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 66
Code:
if (flag1 == 1) {
    if (flag2 == 1) {
	if (flag4 == 1) {
	    if (flag5 == 1) {
		//##################For Loops##########################
		for (i = 0; i < cnt1; i++) {
		    sum1 = sum1 + vel1[i];
		    averagevel1 = sum1 / cnt1;
		}

		for (j = 0; j < cnt2; j++) {
		    sum2 = sum2 + vel2[j];
		    averagevel2 = sum2 / cnt2;
		}

		for (k = 0; k < cnt4; k++) {
		    sum4 = sum4 + vel4[k];
		    averagevel4 = sum4 / cnt4;
		}

		for (l = 0; l < cnt5; l++) {
		    sum5 = sum5 + vel5[l];
		    averagevel5 = sum5 / cnt5;
		}
		//#####################################################

		frontratio = averagevel1 / averagevel4;

		if (frontratio > steerlimit) {
		    slipratio = averagevel2 / averagevel1;

		    if (slipratio > maxslip) {
			torque = (1 - (slipratio - maxslip)) * maxtorque;
			//******Put in serial_printf statement*******
		    } else if (slipratio > threshhold) {
			torque = 0;
		    } else
			torque = 1;

		}

		else if (frontratio < 1 / steerlimit) {
		    slipratio = averagevel5 / averagevel4;

		    if (slipratio > maxslip) {
			torque = (1 - (slipratio - maxslip)) * maxtorque;
			//******Put in serial_printf statement*******
		    } else if (slipratio > threshhold) {
			torque = 0;
		    } else
			torque = 1;
		}

		else {
		    slipratio =
			(averagevel1 + averagevel4) / (averagevel5 +
						       averagevel2);
		    if (slipratio > maxslip) {
			torque = (1 - (slipratio - maxslip)) * maxtorque;
			//******Put in serial_printf statement*******
		    } else if (slipratio > threshhold) {
			torque = 0;
		    } else
			torque = 1;

		}

	    }			//####### This is for flag5
	}			//######## This is for flag4
    }				//######## This is for flag2
}				//####### This is for flag1
Use the code blocks to put code in a post I'm looking through to see if I can spot the problem...
 
Old 12-05-2004, 11:31 PM   #3
illiniguy3043
Member
 
Registered: May 2004
Location: Illinois
Distribution: Ubuntu 8.04
Posts: 56

Original Poster
Rep: Reputation: 15
Sorry about that If you come up with anything let me know, thanks.
 
Old 12-06-2004, 02:06 AM   #4
tamtam
Member
 
Registered: May 2004
Distribution: Slackware.
Posts: 315

Rep: Reputation: 30
else if (frontratio < 1 / steerlimit) {

would be easier (remember precedence)

else if (frontratio < ( 1 / steerlimit )) {
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
MySQL syntax problem Hydrap Linux - Software 1 08-11-2005 10:49 PM
java code executing SQL statements problem randomx Programming 1 11-09-2004 10:59 AM
if statements and case statements not working in bourne shell script mparkhurs Programming 3 06-12-2004 02:41 AM
Syntax problem thort Linux - Newbie 9 12-22-2003 03:08 PM
syntax problem jackopa Linux - Software 0 05-07-2002 11:22 PM


All times are GMT -5. The time now is 09:05 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration