别认识我 发表于 2020-11-30 21:19:40

为什么用>= 运行结果不能出来

#include<stdio.h>
main()
{
        int score;
        printf("input a score:");
        scanf("%d\n",&score);
        if (score<60)
                {
                        printf("The score is E");
                }
        else if (score>=60&&score<70)
                {
                        printf("The score is D");
                }
        else if (score>=70&&score<80)
                {
                        printf("The score is C");
                }
        else if (score>=80&&score<90)
                {
                        printf("The score is B");
                }
        else
                {
                        printf("The score is A");
                }
               
}

jackz007 发表于 2020-11-30 21:26:25

      这一句是错的
      scanf("%d\n",&score);
      必须改成这样
      scanf("%d",&score);

小甲鱼的铁粉 发表于 2020-11-30 21:27:09

scanf里面别要\n了,它没有什么用{:10_250:}
#include<stdio.h>
main()
{
      int score;
      printf("input a score:");
      scanf("%d",&score);
      if (score<60)
                {
                        printf("The score is E");
                }
      else if (score>=60&&score<70)
                {
                        printf("The score is D");
                }
      else if (score>=70&&score<80)
                {
                        printf("The score is C");
                }
      else if (score>=80&&score<90)
                {
                        printf("The score is B");
                }
      else
                {
                        printf("The score is A");
                }
               
}


别认识我 发表于 2020-11-30 21:30:22

小甲鱼的铁粉 发表于 2020-11-30 21:27
scanf里面别要\n了,它没有什么用

\n不是换行吗?

别认识我 发表于 2020-11-30 21:32:18

jackz007 发表于 2020-11-30 21:26
这一句是错的

      必须改成这样

\n 不是换行吗?怎么不行?

jackz007 发表于 2020-11-30 21:35:30

别认识我 发表于 2020-11-30 21:32
\n 不是换行吗?怎么不行?

       printf() 里面可以这么用,scanf() 里面除了格式描述符以外,最好不要有任何其它字符,否则,键盘输入的时候容易出现莫名其妙的现象。

别认识我 发表于 2020-11-30 21:37:05

jackz007 发表于 2020-11-30 21:35
printf() 里面可以这么用,scanf() 里面除了格式描述符以外,最好不要有任何其它字符,否则,键盘 ...

好,谢谢

Dadong丶 发表于 2020-11-30 21:42:33

我正常运行了啊~

Dadong丶 发表于 2020-11-30 21:43:23

你把scanf 括号里的 换行符\n删掉。再试试
页: [1]
查看完整版本: 为什么用>= 运行结果不能出来