| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 524 人关注过本帖
标题:怎样让这个程序可以循环,我本身已经有设置循环了且直到遇到#,但是似乎没用 ...
只看楼主 加入收藏
阿贞小朋友
Rank: 1
等 级:新手上路
帖 子:25
专家分:0
注 册:2014-3-16
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:10 
怎样让这个程序可以循环,我本身已经有设置循环了且直到遇到#,但是似乎没用!
/**********************************
*功能:判断输入的成绩的等级        *
*作者:                            *
*时间:2014\03\27                  *
*                                 *
**********************************/
#include <stdio.h>
#include <ctype.h>
int main (void)
{
    int score ; //表示输入的成绩
    printf("Please enter score:");
    scanf("%d",&score);
    while (score != '#')
    {
        if(score < 0 || score>100)
            printf("The score is fault.\n");
    else
        {
            switch(score / 10)
            {
                case 10 :
                     printf("This student's score is %d and his grade is A .\n ",score);
                     break ;
                case 9 :
                    printf("This student's score is %d and his grade is A .\n ",score);
                    break ;
                case 8 :
                    printf("This student's score is %d and his grade is B .\n ",score);
                     break ;
                case 7 :
                    printf("This student's score is %d and his grade is C .\n ",score);
                     break ;
                case 6 :
                     printf("This student's score is %d and his grade is D .\n ",score);
                     break ;
                default:
                    printf("This student's score is %d and his grade is E .\n ",score);
                    break ;
            }
            break;
        }
        
        scanf("%d",&score);
        continue ;
    }
    return 0;
}
搜索更多相关主题的帖子: include 2014 
2014-03-29 10:25
阿贞小朋友
Rank: 1
等 级:新手上路
帖 子:25
专家分:0
注 册:2014-3-16
收藏
得分:0 
比如我输入 -90 87 110
就要输出
The score is fault.
This student's score is 87 and his grade is B
The score is fault.



但是我这个程序执行后只有
The score is fault.
This student's score is 87 and his grade is B
就结束了
这是为什么?
哪里有问题?
2014-03-29 10:29
ying8501
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
威 望:6
帖 子:1092
专家分:1446
注 册:2008-11-24
收藏
得分:5 
条件换成:score != -1  分数不该是负数。
2014-03-29 10:41
ying8501
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
威 望:6
帖 子:1092
专家分:1446
注 册:2008-11-24
收藏
得分:5 
score是int型的。score != '#'比较时,比较的是'#'的ASCII码。不是你所想的能接收字符。
2014-03-29 10:44
ying8501
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
威 望:6
帖 子:1092
专家分:1446
注 册:2008-11-24
收藏
得分:5 
如果需要处理负数,参看下面程序:
/**********************************
*功能:判断输入的成绩的等级        *
*作者:                            *
*时间:2014\03\27                  *
*                                 *
**********************************/
#include <stdio.h>
#include <ctype.h>
int main (void)
{
    int score ; //表示输入的成绩

    printf("Please enter score:");
   

    while (scanf("%d",&score)!=EOF)  //输入ctr+z时结束
    {
        if(score < 0 || score>100)
            printf("The score is fault.\n");
    else
        {
            switch(score / 10)
            {
                case 10 :
                     printf("This student's score is %d and his grade is A .\n ",score);
                     break ;
                case 9 :
                    printf("This student's score is %d and his grade is A .\n ",score);
                    break ;
                case 8 :
                    printf("This student's score is %d and his grade is B .\n ",score);
                     break ;
                case 7 :
                    printf("This student's score is %d and his grade is C .\n ",score);
                     break ;
                case 6 :
                     printf("This student's score is %d and his grade is D .\n ",score);
                     break ;
                default:
                    printf("This student's score is %d and his grade is E .\n ",score);
                    break ;
            }
         
        }
   
    }
    return 0;
}
2014-03-29 10:50
阿贞小朋友
Rank: 1
等 级:新手上路
帖 子:25
专家分:0
注 册:2014-3-16
收藏
得分:0 
嗯,好!
可是为什么不能这样?
我输入:-90 87 46 101 Ctrl+z
然后程序先对前面的处理,在最后碰到了  Ctrl+z直接结束呢。
而是再次单独输入一个 Ctrl+z才能结束呢?
2014-03-29 11:34
ying8501
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
威 望:6
帖 子:1092
专家分:1446
注 册:2008-11-24
收藏
得分:2 
Ctrl+z是否单独输入都可以。
2014-03-29 12:51
ying8501
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
威 望:6
帖 子:1092
专家分:1446
注 册:2008-11-24
收藏
得分:2 
我在4楼应经说了你程序出错的原因了:
  score是int型的。score != '#'比较时,比较的是'#'的ASCII码。不是你所想的能接收字符。

另外,Ctrl+z是按组合键,即,同时按Ctrl键和z键。
“我输入:-90 87 46 101 Ctrl+z”--- 很少这样表述的。
2014-03-29 12:56
阿贞小朋友
Rank: 1
等 级:新手上路
帖 子:25
专家分:0
注 册:2014-3-16
收藏
得分:0 
我就是在改过的程序中进行的
就是运行后的黑色框中啊
-90 87 46 101 Ctrl+z(这个是同时的,会变成^z)
在101后不能结束
是在我再次输入Ctrl+z(这个是同时的,会变成^z)才能结束
2014-03-29 13:16
ying8501
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
威 望:6
帖 子:1092
专家分:1446
注 册:2008-11-24
收藏
得分:1 
那就打回车之后再输入比较保险一点。
2014-03-29 13:21
快速回复:怎样让这个程序可以循环,我本身已经有设置循环了且直到遇到#,但是似 ...
数据加载中...
 
   



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

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