求高手帮忙写个C语言代码!!超级紧急!!

菜鸟完全不会写QAAAAAAAAAQ求救啊!!!
问题如下:
一位退休人士在银行户口存入360000块,该银行的存款利率(年息)是4%,并于年尾结算年息。假设那人每年会从户口取出一定金额(在年尾结算年息之后),并根据通货膨胀率(为2%不变)增加拿出的金额,例如首年拿走50000块,第二年拿走51000块,第三年拿走52020块等等,请编写一个C程序计算以及列出当尝试提取的金额大于帐户余额时的年数。(计算所需多少年提取的金额会大于帐户余额)

int main()
{
float base=360000;
int year=1;
float get=50000;
while(1)
{
base=base+base*0.04;
get=get+get*0.02;
if(get>base)
{
printf("\n%第%d年拿走%.2f, 余额:%.2f  已超过余额!",year+1,get,base);
break;
}
base-=get;
printf("\n%第%d年拿走%.2f, 余额:%.2f",year+1,get,base);
year++;
}
return 0;
}

温馨提示:答案为网友推荐,仅供参考
第1个回答  2018-10-02
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <signal.h>

#define InflationRate 0.02
#define DepositRate 0.04

void Deposit(unsigned long amount);
void Withdraw(unsigned long amount);
void Interest(double percentage);
unsigned long Saving(void);

int main(int argc, char *argv[])
{
unsigned long year = 1;
unsigned long withdrawal = 50000;

Deposit(360000);
do
{
Interest(DepositRate);
unsigned long saving = Saving();

if(saving < withdrawal)
{
fprintf(stdout, "Year %lu: saving %lu withdrawal %lu", year, saving, withdrawal);
break;
}

Withdraw(withdrawal);

year++; withdrawal *= 1.0 + InflationRate;
}while(1);

return EXIT_SUCCESS;
}

/* ------- Hiden ------- */

static unsigned long cashInBank = 0u;

void Deposit(unsigned long amount)
{
cashInBank += amount;
}

void Withdraw(unsigned long amount)
{
if(amount > cashInBank)
raise(SIGINT);
cashInBank -= amount;
}

void Interest(double percentage)
{
if(percentage < 0)
raise(SIGINT);
cashInBank *= 1.0 + percentage;
}

unsigned long Saving(void)
{
return cashInBank;
}

本回答被提问者和网友采纳