Why is year 0 interest outputting rubbish! C programming?

PraetorianGuard

New member
Joined
Sep 10, 2009
Messages
2
Reaction score
0
Points
1
When i compile with gcc on cygwin it ouput a huge number for year 0 interest, does anyone know why? here is my source code


/* Bank.c
*****************************************************************
Bank.c is desinged to simulate a cash flow situation for a
retiree. Bank.c takes into account for interst, taxes,
living expenses, inflation and the amount of money in the bank.
*/

#include <stdio.h>

int main()
{

printf("Bank.c");
printf("\nA program which simulates a cash-flow for a retiress\n\n\n");
// Intitalise Variables

float bank,interestrate,taxrate,livingexp,initliving,inflationrate,interest,taxout;
int year;

//------------------------------------------------------------------------
// User input of Variables
//------------------------------------------------------------------------

// Initial Savings
printf("Inital deposit to bank: ");
scanf("%f",&bank);

// Interest Rate
printf("Rate of compound interest (%%): ");
scanf("%f",&interestrate);
// Must divide percentage by 100 for a decimal
interestrate=interestrate/100.0;

//Tax Rate
printf("Taxation Percentage on earnings: ");
scanf("%f",&taxrate);
taxrate=taxrate/100.0;

// Initial Living Expenses
printf("Initial Living Expenses: ");
scanf("%f",&livingexp);

// Inflation Rate
printf("Rate of Inflation percentage: ");
scanf("%f",&inflationrate);
inflationrate=inflationrate/100.0;

//-----------------------------------------------------------------------------
// Simulation
//-----------------------------------------------------------------------------

year=0;
printf("\nYear SavingsLiving Expenses Interest Tax");
while (year<=10)
{
printf("\n %2d %8.2f %8.2f %8.2f %8.2f",year,bank,livingexp,interest,taxout);
interest=bank*interestrate;
taxout=interest*taxrate;
bank=bank+interest-taxout-livingexp;
livingexp=livingexp+(livingexp*inflationrate);
year++;
}//end of (year<=10) while loop


return 0;
} // End of main function
 
Back
Top