Allright so I know the error in my code is a logic error. I"m not very good at math, and even if i were i'm not sure i would be able to translate it to C.
The problem. Daphne earns 10% simple interest every year and Deirdre earns 5% compound interest. After how many years will Deirdre's balance exceed Daphne.?
I coded it the first time and every thing seemed fine. Then I realised deirdre had to have compound interest. I went through it a couple times, but it might as well be obfuscated code for me at this hour. What if anything Am i doing wrong, becaue my answer can't be right, is it?
Code:
/* the CompoundINTREST.c */
#include <stdio.h>
#define AMNT 100.00
int main(void)
{
float daphneBAL, deirdreBAL, interest;
int year;
/* Format the screen */
printf("Year Daphne\t Deirdre\n");
/*calculate interest */
deirdreBAL = 100.00;
for ( year = 1; year <= 10; year++){
daphneBAL = ( AMNT * 0.10 + AMNT) * year; /* ten percent simple interest */
/* deirdre gets compounded interest */
interest = ( AMNT * 0.05 + AMNT) * year;
deirdreBAL += interest;
printf("%3d %10.2f %10.2f", year, daphneBAL, deirdreBAL);
if ( deirdreBAL > daphneBAL ){ /* is deirde beating daphne yet */
printf("\nDeirdre just beat daphne\n");
break;
}
printf("\n");
}
getchar();
return(0);
}
Thank you (C board);