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);
/*Verify the load resistance*/
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!