gpt4 book ai didi

无法打印出我的函数计算

转载 作者:行者123 更新时间:2023-12-04 05:13:57 25 4
gpt4 key购买 nike

我的任务是将中了 100 万美元头奖的人存入银行,并以他的钱赚取 8% 的年利率。现在,在每年结束之前,他拉了 10 万。那么他需要多少年才能清空他的账户?

这是我的代码:

#include <stdio.h>
long int year_ended(long int prize);//declare the function to be implemented


int main(void)

{

long int jackpot, years;

jackpot = 1000000;

for (years = 0; jackpot >= 0; years++) //counting the years until the jackpot is 0
year_ended(jackpot);

printf("it will take %ld years to empty the account", years);

return 0;
}

long int year_ended(long int prize) //function to decrement 100k every year and add the erned interest

{
double yearlyRate = 0.08;

int YearlyWithdraws = 100000, left;

left = (prize - YearlyWithdraws) * yearlyRate + (prize - YearlyWithdraws);

prize = left;

return prize;
}

错误是:程序继续运行,但我没有输出..

我做错了什么?

最佳答案

for (years = 0; jackpot >= 0; years++)
year_ended(jackpot);

这是一个无限循环,因为条件始终为真。您可能想要修改 jackpot .类似的东西:
for (years = 0; jackpot >= 0; years++) 
jackpot = year_ended(jackpot);

关于无法打印出我的函数计算,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14547182/

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