Compute the initial investment needed to attain a known future value given : decimal « Data Types « C# / C Sharp






Compute the initial investment needed to attain a known future value given

Compute the initial investment needed to attain 
   a known future value given
  
/*
C#: The Complete Reference 
by Herbert Schildt 

Publisher: Osborne/McGraw-Hill (March 8, 2002)
ISBN: 0072134852
*/

/* Compute the initial investment needed to attain 
   a known future value given annual rate of return 
   and the time period in years. */ 
  
using System;  
  
public class IntialInvestment {     
  public static void Main() {     
    decimal InitInvest; // initial investment 
    decimal FutVal;     // future value 
 
    double NumYears;    // number of years  
    double IntRate;     // annual rate of return as a decimal 
  
    string str;  
 
    Console.Write("Enter future value: "); 
    str = Console.ReadLine(); 
    try {  
      FutVal = Decimal.Parse(str);  
    } catch(FormatException exc) {  
      Console.WriteLine(exc.Message);  
      return;  
    }  
 
    Console.Write("Enter interest rate (such as 0.085): "); 
    str = Console.ReadLine(); 
    try {  
      IntRate = Double.Parse(str);  
    } catch(FormatException exc) {  
      Console.WriteLine(exc.Message);  
      return;  
    }  
 
    Console.Write("Enter number of years: "); 
    str = Console.ReadLine(); 
    try {  
      NumYears = Double.Parse(str);  
    } catch(FormatException exc) {  
      Console.WriteLine(exc.Message);  
      return;  
    }  
 
    InitInvest = FutVal / (decimal) Math.Pow(IntRate+1.0, NumYears);  
  
    Console.WriteLine("Initial investment required: {0:C}", 
                      InitInvest);  
  }     
} 



           
         
    
  








Related examples in the same category

1.Compute the regular payments for a loanCompute the regular payments for a loan
2.Using Decimals
3.Use the decimal type to compute a discount. Use the decimal type to compute a discount.
4.Use the decimal type to compute the future value of an investmentUse the decimal type to compute the future value 
   of an investment
5.Manually create a decimal numberManually create a decimal number
6.decimal property
7.explicit conversions from decimal to int
8.Convert decimal to integer
9.Parse string using "$" as the currency symbol for en-GB and en-us cultures.
10.Rounds a Decimal value to a specified number of decimal places.
11.Decimal.ToDouble
12.Converts Decimal to the equivalent 8-bit unsigned integer.
13.Parse string using "." as the thousands separator and " " as the decimal separator.
14.Converts string to Decimal using the specified style and culture-specific format.
15.Decimal.MinValue Field: represents the smallest possible value of Decimal.
16.Converts the string to its Decimal equivalent
17.Create decimal number from double
18.Decimal.Ceiling Method
19.Returns the TypeCode for value type Decimal.
20.Decimal.ToInt16
21.Converts Decimal to the equivalent 32-bit signed integer.
22.Converts the value of the specified Decimal to the equivalent 64-bit signed integer.
23.Converts Decimal to OLE Automation Currency value
24.Converts Decimal to the equivalent 8-bit signed integer.
25.Converts Decimal to the equivalent single-precision floating-point number.
26.Converts Decimal to string using the specified culture-specific format information.
27.Converts decimal to string using standard format and culture
28.Converts decimal to string to ToString method and format
29.Converts Decimal to the 16-bit unsigned integer.
30.Converts Decimal to the 32-bit unsigned integer.
31.Converts Decimal to 64-bit unsigned integer.
32.Converts string to decimal. A return value indicates whether the conversion succeeded or failed.
33.Parse currency value using en-GB culture.
34.Parse a string to decimal with NumberStyles.AllowDecimalPoint
35.Parse a string to decimal with NumberStyles.AllowDecimalPoint | NumberStyles.AllowThousands
36.Decimal fields: Zero, MinValue, MaxValue, One
37.Converts a Decimal to an 8-bit unsigned integer.