Help! Can't read decimal number
Hi,
I've written the following program, and somehow b'cos of the compiler i'm using. it won't read in a decimal number.
The below file is my fprint.h file , which 'allows' me to read in floats
--------------------------------------------------------------------------------
void Fprint(double,int);
void Fprint(double num,int dec)
{
double num2,num3;
long j,y,z,i;
y=(long)num;
if (dec>0){
i=dec;
dec=1;
while (i>0){
dec=dec*10;
i--;
}
num2=(double)y;
num3=(num-num2)*dec;
z=(long)num3;
num3=((num-num2)*dec)*10;
j=(long)num3;
if (j%10>4){
z++;
}
printf("%ld.%ld ",y,z);
}
else{
printf("%ld ",y);
}
}
---------------------------------------------------------------------------------
#include <stdio.h>
#include <fprint.h>
main()
{
int i;
int balance; /*the amount read in as bank balance*/
int a_interest; /*an annual interest rate read in*/
float value_a; /*interest rate for annually*/
float value_m; /*interest rate for monthly*/
float value_d; /*interest rate for daily*/
float interest;
float balance_a; /*value of bank account in 10yrs after annually*/
float balance_m; /*value of bank account in 10yrs after monthly*/
float balance_d; /*value of bank account in 10yrs after daily*/
printf("Welcome to option [3].\n");
printf("Calculate interest on a bank account balance.\n\n");
printf("Please enter your bank account balance: ");
scanf("%d", &balance);
printf("Please enter an (annual) interest rate: ");
scanf("%d", &a_interest);
interest =(float)a_interest;
value_a =(interest/100) + 1;
value_m =((interest/100)/12) + 1;
value_d =((interest/100)/365) + 1;
balance_a=balance;
balance_m=balance;
balance_d=balance;
for (i = 0; i < 10; i++)
{
balance_a = balance*value_a;
}
for(i = 0; i < 10*12; i++)
{
balance_m = balance*value_m;
}
for(i = 0; i < 10*365; i++)
{
balance_d = balance*value_d;
}
printf("\n");
printf("STATEMENT OF ACCOUNT:\n");
printf("The balance of account in 10 years time adding interest annually is $");
Fprint(balance_a, 2);
printf("\n");
printf("The balance of account in 10 years time adding interest monthly is $");
Fprint(balance_m, 2);
printf("\n");
printf("The balance of account in 10 years time adding interest daily is $");
Fprint(balance_d, 2);
printf("\n\n");
}
-------------------------------------------------
eg: if my initial balance = 100, and interest rate = 5.5
it would read in as 5 only....
Is there any method that I could force it to read in the interest rate ?
thanks!