hey! ok, ive been working on my code and ive managed to sort out my last problem. i just ave one problem left! i want this program to work for any bank transactions therefore for any month so i need to be able to identify how many days are in the month therefore how many days to look at
the code that i have at the moment is:
Code:
#include <stdio.h>
#include <math.h>
int main()
{
FILE *openmr_Smith;
float initialBalance;
int n;
char fileName[50];
float annualInterestRate;
int i;
float currentBalance, dailyInterestRate, dailyInterest[40], totalInterest, min, max;
float charges;
float endBalance;
int thisMonth;
int daysInMonth;
int monthDays[12]={31,28,31,30,31,30,31,31,30,31,30,31};
struct transactions {
int day;
int month;
int year;
float transaction;
};
struct transactions Data[100];
printf("Please enter the filename: ");
scanf("%s",fileName);
openmr_Smith=fopen((fileName),"r");
if (openmr_Smith==NULL) {
printf("This file name is not recognised");
} else {
printf("Please enter the annual interest rate: ");
scanf("%f",&annualInterestRate);
printf("You entered: %4.2f%%\n",annualInterestRate);
getchar();
printf("Opening file: %s ...\n",fileName);
fscanf(openmr_Smith, "%f", &initialBalance);
for (n=0;n<100;n++)
{
fscanf(openmr_Smith, "%d/%d/%d %f", &Data[n].day, &Data[n].month, &Data[n].year, &Data[n].transaction);
}
fclose(openmr_Smith);
thisMonth=Data[0].month;
daysInMonth=monthDays[thisMonth-1];
printf("%i\n",daysInMonth);
currentBalance=initialBalance;
charges=0;
min=initialBalance;
max=initialBalance;
dailyInterestRate=((log((annualInterestRate/100)+1))/3.65);
totalInterest=0;
for (i=1;i<=daysInMonth;i++)
{
for (n=0;n<100;n++)
{
if(i==Data[n].day)
{
currentBalance=currentBalance+Data[n].transaction;
if((Data[n].transaction<0)&&(currentBalance<0))
{
{
currentBalance=currentBalance-10;
}
charges=charges+10;
printf("%f\n",charges);
}
}
}
if(currentBalance>0)
{
dailyInterest[i]=floor((currentBalance/100)*dailyInterestRate*100);
totalInterest=totalInterest+(dailyInterest[i]/100);
}
if(currentBalance<min)
{
min=currentBalance;
}
if(currentBalance>max)
{
max=currentBalance;
}
printf("%4.2f\n",currentBalance);
printf("%f\n",totalInterest);
}
endBalance=currentBalance+totalInterest;
printf("Start balance: %4.2f\n",initialBalance);
printf("End balance: %4.2f\n",endBalance);
printf("Maximum balance: %4.2f\n",max);
printf("Minimum balance: %4.2f\n",min);
printf("Interest paid: %4.2f\n",totalInterest);
printf("Charges incurred: %4.2f\n",charges);
}
return 0;
}
i have highlighted the bits in orange what im looking at, its does produce the correct number of days "30" because im looking at april but as soon as i put it in the loop the information im printing off is no longer correct. But if i type "30" in the loop it works fine would there be any reason for this?