第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;
}本回答被提问者和网友采纳