# Thread: is debugging syntax error really this hard??

1. ## is debugging syntax error really this hard??

Code:
```/*Team 6

for Nam Nguyen,

*/

#include <stdio.h>
#include <math.h>

#define R1 100 /* R1 value never changes, so it becomes a constant*/

int main()
{
int R2, RL;
float current, voltage;
double PR1;  /*power consumed by R1*/
double PR2;  /*power consumed by R2*/
double PRL;  /* power consumed by RL*/

/* All input resistance values will be in ohms */

/*Ask user for value if R2: */
R2_Input: printf("Please enter the value of R2 in ohms: /n" );
scanf("%d", &R2);

/*Check the input*/
if (R2<0 II R2>10000)
{
printf("R2 must be between 0 and 10,000 ohms; please enter another value: /n" );
goto R2_Input;
}
/*Ask the user to enter the value of RL: */
RL_Input :printf("Please enter the value for RL in ohms: /n" );
scanf("%d", &RL);

if (RL <100 II RL > 5000)
{
printf("The value of RL must be between 100 and 5000 ohms inclusive; please enter another value: /n" );
goto RL_Input;
}

/*Ask the user for the value of the voltage source: */
Volt_Input :printf("Please enter the value of the voltage source in volts: /n");
scanf("%.1f", &voltage);

/*Verify the range of the voltage: */
if(voltage < 1 && voltage > 15)
{
printf("The voltage value must be between 1 and 15 to the nearest tenth. Please enter another value: /n");
goto Volt_Input;
}

/* Calculate the current: */
current = voltage/(R1 + R2 + RL);

/*Power is calculated in watts*/
/*Calculate the power for R1: */
PR1 = R1*pow (current, 2);

/*Calculate the power for R2: */
PR2 = R2*pow (current, 2);

/*Calculate the power for RL: */
PRL = RL*pow(current, 2);

/*Construct output table for the current and all power values: */
printf("/tCurrent /t /t/t PR1/t PR2/t prl/n");
printf("/n");
printf("/t%10.4f/ t/t/t%10.4f/t%10.4f/n", current, PR1, PR2, PRL);

/*Output message: */
if (PR1+PR2) ==PRL)
{
printf("NOTE: (PR1 + PR2) = PRL /n");
}
else
{
printf("NOTE: (PR1 + PR2)  != PRL /n");
}

getchar();
return(0);
}```

Building c3.obj.
C:\Documents and Settings\11078378\My Documents\c3.c(27): error #2001: Syntax error: expected ')' but found 'II'.
C:\Documents and Settings\11078378\My Documents\c3.c(27): error #2048: Undeclared identifier 'II'.
C:\Documents and Settings\11078378\My Documents\c3.c(27): error #2001: Syntax error: expected ';' but found 'R2'.
C:\Documents and Settings\11078378\My Documents\c3.c(27): error #2001: Syntax error: expected ';' but found ')'.

hey, this is my first post. I'm new to c, but I'm having trouble understanding syntax errors. From what ive read, it means ive made a mistake on a grammar problem. I dbl checked most of the stuff up top and they seem to match the program codes from the book. i don't undertand the problem. can someone offer a set of fresh eyes please. thanks!

2. Logical OR is || ('pipe' character), not II (capital i)

3. Code:
`II`
is not the same as

Code:
`||`
The second is the logical or operator.

Tim S

4. > if (R2<0 II R2>10000)
I'm guessing you mean ||
This is vertical bar, not upper-case I

Oh, and you should replace your goto with a while loop.

5. And fwiw... no debugging syntax errors is not difficult...

Code:
```C:\Documents and Settings\11078378\My Documents\c3.c(27): error #2001: Syntax error: expected ')' but found 'II'.
C:\Documents and Settings\11078378\My Documents\c3.c(27): error #2048: Undeclared identifier 'II'.
C:\Documents and Settings\11078378\My Documents\c3.c(27): error #2001: Syntax error: expected ';' but found 'R2'.
C:\Documents and Settings\11078378\My Documents\c3.c(27): error #2001: Syntax error: expected ';' but found ')'.```
Filename
Line Number
Error report

Open the file, go to the line number... fix the reported error.

6. Additionally, as a style note, too much commenting is as bad as no comments at all. In your case all the comments take away the readability of the code and make it harder to find errors. Unless you are specifically instructed to comment every line, don't.

7. Originally Posted by nanoguy330
Code:
```R2_Input: printf("Please enter the value of R2 in ohms: /n" );
scanf("%d", &R2);

/*Check the input*/
if (R2<0 II R2>10000)
{
printf("R2 must be between 0 and 10,000 ohms; please enter another value: /n" );
goto R2_Input;
}```
Ah ohh goto statment. Never seen them in a while. You know it rather not a good practice using goto statment. You can get away with using loops? Like something bellow

Code:
```do
{
printf("Please enter the value of R2 in ohms: /n" );
scanf("%d", &R2);
} while( R2<0 || R2>10000 );```
ssharish

8. Originally Posted by AndrewHunter
Additionally, as a style note, too much commenting is as bad as no comments at all. In your case all the comments take away the readability of the code and make it harder to find errors. Unless you are specifically instructed to comment every line, don't.
While I do agree with you... It may look quite different in a syntax highlighting editor...

I typically quote the daylights out of my code, because I know that a year from now I will find parts of it hard to follow... But notice how the comments are faded so as not to interfere with readability....

Now if he's working plain text or hands that over to someone working plain text, yep, that's way too much commenting and it definately does make it harder to follow his code...

And... eyuck... I see goto! Not good.

9. Right angle lines all over the code.

10. Originally Posted by CommonTater
While I do agree with you... It may look quite different in a syntax highlighting editor...

I typically quote the daylights out of my code, because I know that a year from now I will find parts of it hard to follow... But notice how the comments are faded so as not to interfere with readability....
I do agree that a syntax highlighting editor alleviates some of this, and it is a style point hence everyone is allowed to come up with their own practice. I just don't necessarily see anything added by comments that echo what the code is doing. If proper descriptive variable names are used, you shouldn't required a "this line calculates power" comment. In fact in the OPs code his comments didn't expand on anything, he didn't even bother to explain what R1 is in his comment. Additionally, I see very little use in "this line prints output" followed by a printf() statement. But again, just my opinion.

Originally Posted by CommonTater
And... eyuck... I see goto! Not good.
Haha....now this is where a syntax editor would come in handy. It should automatically highlight and bold goto in red and then insert a frowny face at the end of the line.

11. Originally Posted by whiteflags
Right angle lines all over the code.
Nope... only there when the cursor is on a brace... (In Pelles, anyway) ... the dotted line connects to the matching brace.
Move the cursor off the brace... line gone.

12. Originally Posted by AndrewHunter
I do agree that a syntax highlighting editor alleviates some of this, and it is a style point hence everyone is allowed to come up with their own practice. I just don't necessarily see anything added by comments that echo what the code is doing. If proper descriptive variable names are used, you shouldn't required a "this line calculates power" comment. In fact in the OPs code his comments didn't expand on anything, he didn't even bother to explain what R1 is in his comment. Additionally, I see very little use in "this line prints output" followed by a printf() statement. But again, just my opinion.
Oh, hey... I'm not disagreeing... I know I sometimes overcomment ... I mean //show pathname and then perfectly obvious code... but like everything else about me it's a "Rogue" habit I've somehow gotten into... In my own defense, I wrote a whole 10 line function with no comments this morning...

Haha....now this is where a syntax editor would come in handy. It should automatically highlight and bold goto in red and then insert a frowny face at the end of the line.
I'm just waiting until they make that into the syntax error it should be...

My all time favorite goto found in some old Turbo C code I downloaded while learning...
Code:
```// bunch of stuff.

if (input == NULL)
goto Oh_F***_This_Is_All_Wrong;

// about 5 more lines of code

Oh_F***_This_Is_All_Wrong :
Exit (1);```
And I'm betting you can guess what to substitute for the stars...

13. Originally Posted by CommonTater
And I'm betting you can guess what to substitute for the stars...
"ool" - lol

In any case, goto is of the level of inline asm, and should be used at most equally sparingly.

14. >> ... so as not to interfere with readability...
The main interference with readability is the bracing style (post #5). At a minimum, closing braces should be first on the line, and in the same column of the statement that started the block. Discerning the scope should be as easy as possible, not a bracket hunt.

gg

15. Originally Posted by iMalc
"ool" - lol

In any case, goto is of the level of inline asm, and should be used at most equally sparingly.
Hint: There's a "c", a "k" and a "u" in there... but not necessarily in that order.

LOL....