黑马程序员技术交流社区

标题: 求解,为何出错 [打印本页]

作者: Dast    时间: 2015-6-9 13:20
标题: 求解,为何出错
本帖最后由 Dast 于 2015-6-9 16:54 编辑

#include <stdio.h>

int main(int argc, const char * argv[]) {
    // insert code here...
    int score = 0;
    printf("input score please:");
    do {
        scanf("%d",&score);
    } while( score<0 || score > 100);
     if (score <= 60){
        printf("the score is E");
    }else if (score <= 80){
        printf("score is B");
    }else if (score <= 100){
        printf("score is A");
    }
       return 0;
}

作者: Dast    时间: 2015-6-9 13:21
难道是我打开的方式不对?
作者: tabor    时间: 2015-6-9 14:50
score<0 || score > 100, 这里要改下,应当是score>=0 && score <=100
作者: 晗修    时间: 2015-6-9 14:55
直到循环和当循环的区别
还有就是这里最好不要这样写循环,没有任何提示 输错一次继续scanf,别人根本不知道要做什么。
作者: 白0702    时间: 2015-6-9 15:12
你这个函数没什么问题,就是那个do while最好别这么写,你这么写如果输入负数或者>100的数,别人不知道该怎么做了。
作者: Elors    时间: 2015-6-9 16:36
写法是没问题的,你可以检查一下你工程里的符号是否是英文符号。
作者: Dast    时间: 2015-6-9 16:52
Elors 发表于 2015-6-9 16:36
写法是没问题的,你可以检查一下你工程里的符号是否是英文符号。

的确是,while里面有中文输入法的字母,重写就ok了。谢谢
作者: Dast    时间: 2015-6-9 16:53
白0702 发表于 2015-6-9 15:12
你这个函数没什么问题,就是那个do while最好别这么写,你这么写如果输入负数或者>100的数,别人不知道该怎 ...

int score = -1;
     do
    {
        printf("input score please:");
        scanf("%d",&score);
    }while(score<0 ||score>100);
改成这样就知道干嘛了,嘻嘻




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2