简体   繁体   中英

Not getting the expected output (compound interest calculator)

The expected output if I enter £100, 0.10, 10 (10 years) should be £259.37, but I'm getting 100.00000001000001

using System;
using System.Security.Cryptography;

namespace compound_interest
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("Please enter the amount of money that is being compounded! ");
            double P = Convert.ToDouble(Console.ReadLine());
            Console.Write("Please enter the amount of interest (write it is 0.10 for 10% etc!! ");
            double MP2 = Convert.ToDouble(Console.ReadLine());
            Console.Write("Please enter the number of years");
            double Y = Convert.ToDouble(Console.ReadLine());
            double MP1 = Convert.ToDouble(Math.Pow(MP2, Y));
            double MP = (MP1) + 1;
            double A = (P) * (MP);
            Console.WriteLine(A);
        }
    }
}

Before you do this

 double MP1 = Convert.ToDouble(Math.Pow(MP2, Y));

Do this

 MP2 = 1 + MP2

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM