gpt4 book ai didi

c - 如何在 while 循环中扫描多个输入?

转载 作者:行者123 更新时间:2023-11-30 17:57:49 25 4
gpt4 key购买 nike

while((player1chip==-1)||(player2chip==-1)||(player3chip==-1)){                                                              
player1chip=-1; player2chip=-1; player3chip=-1;
printf("How many chips would you like to play with (3-10):\n");
scanf("%d%d%d", &player1chip, &player2chip, &player3chip);
getchar();
}

我想一次获取 3 个值,但循环似乎已经运行了 3 次...我应该怎么做?

最佳答案

int p1chip=-1, p2chip=-1, p3chip=-1;
do {
printf("How many chips would you like to play with (3-10)?\n");
scanf("%d%d%d", &p1chip, &p2chip, &p3chip);
} while ((p1chip == -1) || (p2chip == -1) || (p3chip == -1))

尝试一下。

关于c - 如何在 while 循环中扫描多个输入?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12612831/

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