作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
所以我正在为简单的形状确定程序编写这段代码,我试图循环它,循环结束的条件是变量 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/
我是一名优秀的程序员,十分优秀!