![]() |
| | #1 |
| Guest
Posts: n/a
| Help! Can't read decimal number 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! |
|
| | #2 |
| Mayor of Awesometown Join Date: Aug 2001 Location: MI
Posts: 8,826
| Change your %d to %f... |
| Govtcheez is offline | |
| | #3 |
| Guest
Posts: n/a
| I'm using a compiler known as pacifc c by hitech, the url is http://www.hitech.com.au/products/pacific.html somehow, when i changed the %d to %f and declares a_interest to a float, it won't let me enter a sum after i entered my balance. my compiler doesnt read in floats, is there any way i could force the int to umm something then convert it back to the total i want say entered 5.5, read in and a_interest * 100 = x annual balance = x /100 etc im not sure. just a thought. |
|
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| trouble with creating a loop to read certain number of inputs | import tuner650 | C++ Programming | 2 | 03-20-2008 07:28 PM |
| how to read hard disk serial number | toufiq_raja | C Programming | 4 | 08-18-2005 10:08 PM |
| how to read hard disk serial number | toufiq_raja | C++ Programming | 3 | 08-18-2005 04:32 AM |
| Prime number program problem | Guti14 | C Programming | 11 | 08-06-2004 04:25 AM |
| finding the decimal part of a number | Geo-Fry | C++ Programming | 13 | 07-31-2003 12:43 PM |