Jul 8, 2025
Оfftopic Community
Оfftopic Community
Forums
New posts
Search forums
What's new
Featured content
New posts
New media
New media comments
New resources
New profile posts
Latest activity
Media
New media
New comments
Search media
Resources
Latest reviews
Search resources
Members
Current visitors
New profile posts
Search profile posts
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
OffTopic Community
Random Interesting Topics
Why is year 0 interest outputting rubbish! C programming?
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="PraetorianGuard" data-source="post: 1988053" data-attributes="member: 722698"><p>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</p><p></p><p></p><p>/* Bank.c </p><p>*****************************************************************</p><p>Bank.c is desinged to simulate a cash flow situation for a</p><p>retiree. Bank.c takes into account for interst, taxes,</p><p> living expenses, inflation and the amount of money in the bank.</p><p>*/</p><p></p><p>#include <stdio.h></p><p></p><p>int main()</p><p>{</p><p></p><p>printf("Bank.c");</p><p>printf("\nA program which simulates a cash-flow for a retiress\n\n\n");</p><p>// Intitalise Variables</p><p></p><p>float bank,interestrate,taxrate,livingexp,initliving,inflationrate,interest,taxout;</p><p>int year;</p><p></p><p>//------------------------------------------------------------------------</p><p>// User input of Variables</p><p>//------------------------------------------------------------------------</p><p></p><p>// Initial Savings</p><p>printf("Inital deposit to bank: ");</p><p>scanf("%f",&bank);</p><p></p><p>// Interest Rate</p><p>printf("Rate of compound interest (%%): ");</p><p>scanf("%f",&interestrate);</p><p>// Must divide percentage by 100 for a decimal</p><p>interestrate=interestrate/100.0;</p><p></p><p>//Tax Rate</p><p>printf("Taxation Percentage on earnings: ");</p><p>scanf("%f",&taxrate);</p><p>taxrate=taxrate/100.0;</p><p></p><p>// Initial Living Expenses</p><p>printf("Initial Living Expenses: ");</p><p>scanf("%f",&livingexp);</p><p></p><p>// Inflation Rate</p><p>printf("Rate of Inflation percentage: ");</p><p>scanf("%f",&inflationrate);</p><p>inflationrate=inflationrate/100.0;</p><p></p><p>//-----------------------------------------------------------------------------</p><p>// Simulation</p><p>//-----------------------------------------------------------------------------</p><p></p><p>year=0;</p><p>printf("\nYear SavingsLiving Expenses Interest Tax");</p><p>while (year<=10)</p><p>{</p><p>printf("\n %2d %8.2f %8.2f %8.2f %8.2f",year,bank,livingexp,interest,taxout);</p><p>interest=bank*interestrate;</p><p>taxout=interest*taxrate;</p><p>bank=bank+interest-taxout-livingexp;</p><p>livingexp=livingexp+(livingexp*inflationrate);</p><p>year++;</p><p>}//end of (year<=10) while loop</p><p></p><p></p><p>return 0;</p><p>} // End of main function</p></blockquote><p></p>
[QUOTE="PraetorianGuard, post: 1988053, member: 722698"] 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 [/QUOTE]
Insert quotes…
Name
Verification
Please enable JavaScript to continue.
Loading…
Post reply
Top