using System;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
try
{
Console.Write("Input a monthly saving amount:");
string str = Console.ReadLine();
double amountSaving = float.Parse(str);
const double rate = 0.00417f;
int qtyMonth = 6;
double account = 0;
for (int i = 1; i <= qtyMonth; i++)
{
account = (amountSaving + account) * (1 + rate);
account = Math.Truncate(account * 1000) / 1000; // round by 3 digits
Console.WriteLine("Account value after the {0} month: {1:F3}", i, account);
}
}
catch
{
Console.WriteLine("Bad amount");
return;
}
}
}
}
Comments
Leave a comment