| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 412 人关注过本帖
标题:检查不出问题,请大家不吝赐教。
只看楼主 加入收藏
jiangchuanze
Rank: 2
等 级:论坛游民
帖 子:8
专家分:13
注 册:2012-1-19
收藏
 问题点数:0 回复次数:2 
检查不出问题,请大家不吝赐教。
/*output the student score in A,B,C,D,E class*/
#include<stdio.h>
#include<stdlib.h>
int main()
{
        int score;
        char ch;
   test:{
        printf("please input the score: ");
        scanf("%d",&score);

        if(score>=90)
                ch='A';
        else if(score>=80&&score<=89)
                ch='B';
        else if(score>=70&&score<=79)
                ch='C';
        else if(score>=60&&score<=69)
                ch='D';
        else
                ch='E';

        printf("this student score is : %c class\n",ch);
     test2:  {
        printf("continue the test , Y/N ? : ");
        char judge='Y';
        scanf("%c",&judge);
        if(judge=='Y'||judge=='y')
                goto test;
        else if(judge=='N'||judge=='n')
                exit(0);
        else
                printf("Error :wrong input!!!!!!!! \n");
                goto test2;
       }
}

return 0;
}

输入23后,运行结果
please input the score: 23
this student score is : E class
continue the test , Y/N ? : Error :wrong input!!!!!!!!
continue the test , Y/N ? :
 
请大家分析一下为什么会出现continue the test , Y/N ? : Error :wrong input!!!!!!!!
搜索更多相关主题的帖子: 检查 class include please 
2012-02-11 19:44
chenliangjs
Rank: 2
等 级:论坛游民
帖 子:34
专家分:89
注 册:2012-1-14
收藏
得分:0 
因为你输入数字后。。。要按回车。。所以judge的第一次读的值就是回车。。。在scanf后面再加个scanf("%c",&judge);,或者getchar (judge);就行了。。。
2012-02-11 20:39
jiangchuanze
Rank: 2
等 级:论坛游民
帖 子:8
专家分:13
注 册:2012-1-19
收藏
得分:0 
回复 2楼 chenliangjs
谢谢,运行正确,但是再请教一下,为什么在按下回车的时候还是要再scanf一次?这样的情况在什么条件下才会发生?
2012-02-16 10:49
快速回复:检查不出问题,请大家不吝赐教。
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.010774 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved