标题:请问我的C程序为什么不能循环运行
取消只看楼主
索马里的蘑菇
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2011-8-8
结帖率:100%
已结贴  问题点数:20 回复次数:2 
请问我的C程序为什么不能循环运行
RT,编译之后只能运行一次,到了应该输入y或者n的时候程序就自动退出了!跪求解答!


#include <stdio.h>
#include <stdlib.h>

int main(void)
{
    char another_game='y';
    printf("Hay man!If you wanna try this,press ENTER!\n");
    scanf("%c",&another_game);
    while(another_game=='y');
    {
        int num1=0,num2=0;
        num1=1+rand()%10;
        printf("Look,all you need to do is type a number from 1~10,and press ENTER.Quite simple,uh?Good luck!\n");
        scanf("%d",&num2);
        if(num2==num1)
        printf("You are doing so well!\n");
        else
        printf("Well,maybe you will be lucky next time\n");
        printf("Another round?y/n");
        scanf("%c",&another_game);
      }

   return 0;
}
搜索更多相关主题的帖子: include number simple 
2011-08-08 00:42
索马里的蘑菇
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2011-8-8
得分:0 
多谢!现在可以用了!
另外想请问一下为什么 scanf("%*c");也可以清除缓冲区?%*c是什么格式符?
2011-08-08 09:09
索马里的蘑菇
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2011-8-8
得分:0 
回6L~谢谢~
2011-08-08 13:17



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-347031-1-1.html




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

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