473,406 Members | 2,894 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Suggestions for Double Declining Depreciation?

Expand|Select|Wrap|Line Numbers
  1.  #include <iostream> 
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. int i, iYears;
  7. float fInitialVal, fSalvageVal;
  8. char cAgain;
  9.  
  10. do
  11. {
  12.      cout << endl << "Please enter an initial value: ";
  13.      cin >> fInitialVal;
  14.      cout << endl << "Please enter a salvage value: ";
  15.      cin >> fSalvageVal;
  16.      cout << endl << "Please enter the number of years to depreciate: ";
  17.      cin >> iYears;
  18.  
  19. cout << endl << endl << "Straight Line" << endl;
  20. cout << endl << "Year Value" << endl;
  21.      for(i = 1; i <= iYears; i++)
  22.      {
  23. fInitialVal = (fInitialVal - fSalvageVal);
  24. cout << endl << i << " " << fInitialVal;
  25.      }
  26.  
  27.      cout << endl << endl << "Double Declining" << endl;
  28.      cout << endl << "Year Value" << endl;
  29.  
  30.      for(i = 1; i <= iYears; i++)
  31.      {
  32. fInitialVal = fInitialVal - fSalvageVal * 2/ iYears;
  33.      cout << endl << i << " " << fInitialVal;
  34.      }
  35. cout << endl << endl << "Would you like to run another"
  36. << " calculation? Y/y/N/n" << endl << endl;
  37. cin >> cAgain;
  38. }while (cAgain == 'Y' || cAgain == 'y');
  39.  
  40. return 0;
  41.  
  42. }
  43.  
  44.  
Ok, my straight line depreciation works correctly but I am having trouble geting my Double Declining to work. I need it to output the numbers under the Year and value not the math. So if anyone has any suggestion for my code they would be appreciated.


Double declining, initial value 12000, salvage value 2000, 5 years.

year value
0 12000
1 8000 (subtracted (12000 - 2000) * (2/5) )
2 5600 (subtracted (8000 - 2000) * (2/5) )
3 4160 (subtracted (5600 - 2000) * (2/5) )
4 3296 (subtracted (4160 - 2000) * (2/5) )
5 2777.6 (subtracted (3296 - 2000) * (2/5) )
Apr 16 '07 #1
1 2151
weaknessforcats
9,208 Expert Mod 8TB
Looks like a job for recursion to me. Recursion is where a function calls itself.

So, you call:

DDepreciation(12000, 5) this functions calls:
DDepreciation(8000, 4) which calls
DDeopreciation(5600, 3) etc.

when the year is 0 the function returns. Consult a textbook for this.

Also, be careful of using floating point in fincance applications. The automatic rounding can throw your books off. In fact, there a laws in Europe prohibiting floating point in trhese types of applications. I would keep my amounts in pennies. Only when I display would I show 12345 as 123.45 by converting the int to a string where I manually insert the decimal point.
Apr 16 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Master of C++ | last post by:
Hello Folks, I have a programming dilemma with templates and "genericity". I can think of a few solutions, but I am not sure which one is the best in terms of genetic C++ style. Any suggestions...
4
by: N. Graves | last post by:
First... thanks for taking time to read my quest. I have Access database that I have created that once it has been deployed I will not know who has it or who is using it. This is my idea but...
193
by: Michael B. | last post by:
I was just thinking about this, specifically wondering if there's any features that the C specification currently lacks, and which may be included in some future standardization. Of course, I...
2
by: nejmay | last post by:
Help Please, I am taking a beginners VB.NET class and my next assignment making a Depreciation Calculator. I am suppose to use the built in functions SLN() and SYD() to perform the calus, option...
2
by: blagdam | last post by:
I am attempting to calculate the book value of assets in a query. I calculate total depreciation of the asset using the built in Strait Line Depreciation function and then use the following...
45
by: Gregory Petrosyan | last post by:
1) From 2.4.2 documentation: There are two new valid (semantic) forms for the raise statement: raise Class, instance raise instance 2) In python: >>> raise NameError Traceback (most recent...
7
by: matt | last post by:
hello, i have been given a challenging project at my org. i work on an inventory management web application -- keeping tracking of parts assigned to projects. in the past, i built an in-house...
1
by: rjoseph | last post by:
Hi guys You've really helped me out in the past but now I really need your help! Basically I have a table (name=vehicletable) with the following fields/field data: Make Model Age ...
3
by: LosLobo | last post by:
Good morning all. This is my first post to the site, and what a wonderful site this is. I wish I had come across it years ago. I am working on a database that is going to track the assets for a...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.