【发布时间】:2021-11-28 23:47:03
【问题描述】:
我正在尝试为初学者做 CS50 的 lab1。我很难理解为什么我的代码不起作用。
向用户询问起始尺寸和结束尺寸可以正常工作。
问题是当我计算达到最终大小所需的年数时,然后显示结果。它不起作用,我看不出它为什么不起作用。
谁能看到我在代码中做错了什么?我看过类似的问题,但我仍然无法理解我做错了什么。
#include <cs50.h>
#include <stdio.h>
// Determine the number of years required for the population to grow from the start size to the end size.
int main(void)
{
// TODO: Prompt for start size. Has to be greater than 9, otherwise ask again.
// TODO: Prompt for end size
int start;
int end;
int years = 0;
int n;
do
{
start=get_int("Give me a start size of the population: ");
end=get_int("Give me a end size of the population: ");
}
while (start<9 || end<start);
return start;
return end;
// TODO: Calculate number of years until we reach threshold
do
{
n = start + (start/3)-(start/4);
start=n;
years++;
}
while (start<end);
return years;
// TODO: Print number of years
printf("The number of years to reach your end population is %i/n", years);
}
【问题讨论】: