Getting the error “expected identifier or ‘(‘ before ‘{‘ token in C

c++token

Any help would be great!

#include <stdio.h>
#define pi 3.14159



int main()
{
  float r;
  char PI;

/*Program for circumference. */

    printf(" This is a program that will calculate circumference.\n");
    printf("Please put in your radius.\n");

    scanf("%f", &r);
    printf("Please input PI\n");
    PI = getchar();
 }

   {
    if {(char != PI || 3.14);
    printf("Incorect value\n");
}

    else {
    printf("Thank you, the circumference is now.\n");
    printf("%f", (r) * pi *2);
}


return 0;

}

I'm trying to figure out this error, I have definitely searched around, but nothing really has popped up with my specific problem. If it helps, it is right before the "if" statement begins. Might I be using one too many '{'?

Best Solution

I have pointed out the errors with comments.Make it a habit to use caps for the #define macro, not for the variables.And finally, the condition for your if should be if(PI!=pi).Remove the { between if and the (, and also the ; after the )

#include <stdio.h>
#define pi 3.14159



int main()
{
  float r;
  char PI;

/*Program for circumference. */

    printf(" This is a program that will calculate circumference.\n");
    printf("Please put in your radius.\n");

    scanf("%f", &r);
    printf("Please input PI\n");
    PI = getchar();
 } //This is the source of error as `main()` ends after this `}'

   {
    if(PI!=pi)  //You have used a `;` after if's condition & an extra '{' before it
    printf("Incorect value\n");
}

    else {
    printf("Thank you, the circumference is now.\n");
    printf("%f", (r) * pi *2);
}


return 0;

}
Related Question