[英]CS50 llamas lab I don't know how to solve it
#include <cs50.h> #include <stdio.h> #include <cs50.h> #include <stdio.h>
int main(void) { int start; int main(void) { int 开始; do { start = get_int("start size: ");
do { start = get_int("起始尺寸:"); } while (start < 9);
} 而(开始 < 9);
int end;
do
{
end = get_int("end size: ");
}
while (end < start);
int year = 0;
do
{
start = start + (start / 3) - (start / 4);//calculate number of years untile we reach thresholㅇ
**year++;**
}
while (start < end);
printf("Years: %i", year);
} }
enter image description here :( handles same starting and ending sizes expected "Years: 0", not "Years: 1"在此处输入图像描述:( 处理相同的起始和结束尺寸,预期为“年:0”,而不是“年:1”
i think year++ is the problem i don't know how to solve it我认为 year++ 是我不知道如何解决的问题
Remember, the do
loop will execute the body and then test the condition (in the while
).请记住,
do
循环将执行主体,然后测试条件(在while
中)。 When start
and end
are both 100, year
will be incremented before it evaluates the while
condition.当
start
和end
均为 100 时, year
将在评估while
条件之前递增。 Since program needs to compare start
and end
before it increments year
, a simple while
loop is appropriate.由于程序需要在递增
year
之前比较start
和end
,所以一个简单的while
循环是合适的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.