-1

任何帮助都会很棒!

#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;

}

我试图找出这个错误,我肯定已经搜索过了,但我的具体问题并没有真正弹出。如果有帮助,就在“if”语句开始之前。我可能使用了太多的“{”吗?

4

2 回答 2

1

您将在第一个}字符处终止您的主要功能。您的左大括号和右大括号的匹配不均匀,这就是导致问题的原因。你的if陈述也有问题。这

if {(char != PI || 3.14);

应该读作

if (char != PI || 3.14)

或者更具体地说,整个 if-else 应该是

if (char != PI || 3.14)
{
   printf("Incorect value\n");
} else {
   printf("Thank you, the circumference is now.\n");
   printf("%f", (r) * pi *2);
}
于 2013-04-27T21:41:13.130 回答
1

我已经用注释指出了错误。养成对#define宏使用大写字母的习惯,而不是对变量使用大写字母的习惯。最后,你的条件if应该是。if(PI!=pi)删除{中间if和之后(,以及;之后)

#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;

}
于 2013-04-27T21:43:04.513 回答