Need assistance with possible syntax error.

This is a discussion on Need assistance with possible syntax error. within the C Programming forums, part of the General Programming Boards category; Hello, I need some assistance in determining the cause of a specific error within my code. The error is: switch ...

  1. #1
    Registered User
    Join Date
    Aug 2012
    Posts
    1

    Exclamation Need assistance with possible syntax error.

    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!

  2. #2
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    1,625
    You have extra semicolons on lines #91 and #101
    Devoted my life to programming...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 11-30-2011, 11:55 AM
  2. Error "in function 'main' syntax error before 'int' Help Please
    By blackhat11907 in forum C Programming
    Replies: 5
    Last Post: 08-20-2011, 08:05 PM
  3. Logic/Runtime Error Assistance ASAP.
    By Pr0AHP in forum C Programming
    Replies: 1
    Last Post: 12-01-2009, 07:15 AM
  4. error C2061: syntax error : identifier
    By maninboots in forum C++ Programming
    Replies: 4
    Last Post: 07-02-2009, 06:40 AM
  5. GCC compiler giving syntax error before 'double' error
    By dragonmint in forum Linux Programming
    Replies: 4
    Last Post: 06-02-2007, 06:38 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21