jeezmorty 2019-02-10 21:37 采纳率: 66.7%
浏览 654
已采纳

C语言基础疑问 代码最后的scanf为什么不执行?

这段代码是一个叫simon的游戏,就是输出任意数码 然后消失 然后请用户输入
但是很奇怪编译执行之后,最后一句printf执行了但是scanf却不执行 为什么
编译器是devc++
// a simple simon game
#include
#include
#include
#include
#include
int main(void)
{
char another_game='Y';
const unsigned delay=1;
bool answer=true;
unsigned tries=0;
unsigned digits=0;
time_t seed=0;
time_t wait_start=0;
unsigned number=0;

printf("To play a Simple Simon,watch the screen for a sequence of digits.");
printf("\nWatch carefully, as the digits are only played for %u second%s.",delay, delay==1?"":"s");
printf("\nThe computer will remove them, then prompt you to enter the same sequence.");
printf("\nWhen you do, you must put space in your digits.");
printf("\nGood luck! Press enter to play.\n");

do
{
    answer=true;
    tries=0;
    digits=2;

    while(answer)
    { 
        ++tries;

        srand(time(&seed));//without & the program goes wrong 
        for(unsigned i=1;i<=digits;++i)
            printf("%d ",rand()%10);//output the number

        wait_start=clock();
        for(;clock()-wait_start<delay*CLOCKS_PER_SEC;);
        printf("\r");
        for(unsigned i=1;i<=digits;++i)
            printf("  ");

        printf("\r");
        if(tries==1)
            printf("make sure enter the space between digits!\n");
        srand(seed);
        for(unsigned i=1;i<=digits;++i)
        {
            scanf("%u",&number);//how to make sure the value of seed is stayed
            if(number!=rand()%10)
            {
                answer=false;
            }
        }

        if(answer&&(tries%3==0))
            digits++;

        printf("%s\n",answer?"correct":"wrong");
    }

    printf("\nDo you want to play again(Y/N)?"); 
    scanf("%c",&another_game);

}while(tolower(another_game)=='y'); 

return 0;

}

  • 写回答

2条回答 默认 最新

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥20 有人知道怎么将vsi格式的图片文件,转换为svs格式的文件吗
      • ¥15 历史模拟法计算var实验报告
      • ¥15 白鲸算法优化K值的VMD分解出错
      • ¥20 写一个基于52单片机用hc-05蓝牙模块控制28BYJ-48步进电机进行旋转,在手机蓝牙串口输入1019电机转半圈,输入2038电机转一圈,输入0复位的代码吗
      • ¥15 求51单片机8位数码管计时器程序
      • ¥20 matlab识别螺母边缘
      • ¥15 python 6x6游戏加登录、记录系统
      • ¥100 基于做一个模拟智慧路灯
      • ¥15 ME21N 创建采购成功并且生成采购订单号,但显示“快件文档更新已取消”,SM13看错误提示为如下截图:
      • ¥30 android 集成fmod实现变声功能中遇到的问题