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