问题
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 '{'?
回答1:
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;
}
回答2:
You are terminating your main function at the first } character. You have an uneven match of open and close braces and that is causing the problem. You also have a problem with your if statement. This
if {(char != PI || 3.14);
should read as
if (char != PI || 3.14)
or more specifically the entire if-else should be
if (char != PI || 3.14)
{
printf("Incorect value\n");
} else {
printf("Thank you, the circumference is now.\n");
printf("%f", (r) * pi *2);
}
来源:https://stackoverflow.com/questions/16257109/getting-the-error-expected-identifier-or-before-token-in-c