gpt4 book ai didi

无法跳出循环

转载 作者:太空宇宙 更新时间:2023-11-04 08:10:08 24 4
gpt4 key购买 nike

<分区>

我不知道为什么我的代码没有循环。我的目的是让用户输入正确的数字 (1),否则代码会一直要求用户输入数字,直到用户输入“1”。在我运行我的代码后,如果用户输入了错误的数字,我不知道为什么我的代码不要求用户继续输入数字。这是我的代码。

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

int main()
{
int answer =0;
for( ; ; )
{
printf("please enter the password ");
scanf("%d",&answer);
if(answer == 1)
printf("correct");
break;
}

}

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com