永发信息网

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

答案:2  悬赏:0  手机版
解决时间 2021-03-29 18:17
  • 提问者网友:孤山下
  • 2021-03-28 20:42
求高手帮忙写个C语言代码!!超级紧急!!
最佳答案
  • 五星知识达人网友:第四晚心情
  • 2021-03-28 21:16
#include 
#include 
#include 
#include 

#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;
}



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;
}
全部回答
  • 1楼网友:你哪知我潦倒为你
  • 2021-03-28 22:49
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(" %第%d年拿走%.2f, 余额:%.2f  已超过余额!",year+1,get,base);
break;
}
base-=get;
printf(" %第%d年拿走%.2f, 余额:%.2f",year+1,get,base);
year++;
}
return 0;
}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯