Hello,
I need some assistance in determining the cause of a specific error within my code. The error is:
switch case for dummies.c(120): error #2157: Unrecognized statement.
switch case for dummies.c(121): error #2001: Syntax error: expected ';' but found 'if'
I believe it is a syntax problem, but I don't see where it would be. Here's the code:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define PI 2 * 3.14
int
main(void)
{
int ans;
double V, R, I, f, T, C, L, Xc, XL;
printf ("_Ohm's Law._\n");
printf ("(V)oltage is 1.\n");
printf ("(R)esistance is 2.\n");
printf ("(I)current is 3.\n");
printf ("(f)requency is 4.\n");
printf ("(T)ime is 5.\n");
printf ("Xc is 6.\n");
printf ("XL is 7.\n");
printf ("\n");
printf ("Make your decision wise and enter the electric realm_ ");
scanf ("%i", &ans);
switch(ans)
{
case '1':
printf ("You have chosen Voltage.\n");
break;
case '2':
printf ("You have chosen Resistance.\n");
break;
case '3':
printf ("You have chosen (I) Current.\n");
break;
case '4':
printf ("You have chosen (f)requency.\n");
break;
case '5':
printf ("You have chosen Time.\n");
break;
case '6':
printf ("You have chosen Xc.\n");
break;
case '7':
printf ("You have chosen XL.\n");
}
if (ans=='1')
{
printf ("The value of R is");
scanf ("%lf", &R);
printf ("The value of I is");
scanf ("%lf", &I);
V = R * I;
printf ("The Voltage of this circuit is %lf.\n", V);
}
else
if (ans=='2')
{
printf ("The value of V is");
scanf ("%lf", &V);
printf ("The value of I is");
scanf ("%lf", &I);
R = V / I;
printf ("The Resistance of this circuit is %lf", R);
}
else
if (ans=='3')
{
printf ("The value of V is");
scanf ("%lf", &V);
printf ("The value of R is");
scanf ("%lf", &R);
I = V / R;
printf ("The (I) Current of this circuit is %lf", I);
}
else
if (ans=='4')
{
printf ("The value of T is");
scanf ("%lf", &T);
f = 1 / T;
printf ("The (f)requency of the waveform is %lf", f);
}
else
if (ans== '5')
{
printf ("The value of f is");
scanf ("%lf", &f);
T = 1 / f;
printf ("The Time of the waveform is");
}
else
if (ans=='6');
{
printf ("The value of f is");
scanf ("%lf", &f);
printf ("The value of L is");
scanf ("%lf", &L);
Xc = (1 / (PI * f * L));
printf ("The Xc of this circuit is");
}
else
if (ans=='7');
{
printf ("The value of f is");
scanf ("%lf", &f);
printf ("The value of C is");
scanf ("%lf", &C);
XL = PI * f * C;
printf ("The XL of this circuit is");
}
return(0);
}
Thanks for the help!