gpt4 book ai didi

c - 尝试在 C 中使用 REPEAT UNTIL (DO...WHILE) 循环

转载 作者:行者123 更新时间:2023-11-30 20:59:35 25 4
gpt4 key购买 nike

所以我正在为简单的形状确定程序编写这段代码,我试图循环它,循环结束的条件是变量 x 的值等于 0(所有变量都是天使) ),由于角度不能为0,所以我认为只有循环循环直到输入的值为0才是符合逻辑的。但是,即使满足条件后,代码似乎也不会停止迭代。代码如下:

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

int main()
{
int x=0;
int y=0;
int A=0;
do {
printf("What is the value of x?");
scanf("%d", &x);
printf("What is the value of y?");
scanf("%d", &y);
printf("What is the value of A?");
scanf("%d", &A);
if ((A==90)&&(x==y))
{
printf("Square\n");
}
else if ((A==90)&&(x!=y))
{
printf("Rectangle\n");
}
else if ((A==60)||(A==120))
{
printf("Hexagonal\n");
}
else if ((A!=60)||(A!=120)&&(x==y))
{
printf("Rhombic\n");
}
else if ((A!=60)||(A!=120)&&(x!=y))
{
printf("Parallelogram\n");
}
else
{
printf("The values you have entered are not supported by the program,
try again!");

}
}while(x!=0);
printf("Thanks for using the program!");



system("pause");
return 0;
}

我实在看不出 while 循环的条件有什么问题,请帮忙!

最佳答案

最简单的方法可能是:

    scanf("%d", &x);
if (!x) break; // break the loop, not asking anything else

关于c - 尝试在 C 中使用 REPEAT UNTIL (DO...WHILE) 循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46958820/

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