Mega Code Archive

 
Categories / C# Tutorial / Data Type
 

Use the decimal type to compute the future value of an investment

using System;      class Example {    public static void Main() {      decimal amount;        decimal rate_of_return;       int years, i;            amount = 100000.0M;      rate_of_return = 0.17M;      years = 100;        Console.WriteLine("Original investment: $" + amount);      Console.WriteLine("Rate of return: " + rate_of_return);      Console.WriteLine("Over " + years + " years");        for(i = 0; i < years; i++) {       amount = amount + (amount * rate_of_return);      }     Console.WriteLine("Future value is $" + amount);     }  } Original investment: $100000.0 Rate of return: 0.17 Over 100 years Future value is $658546088583.68156535520269753