-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 に答える