What is the problem with this code? I'm new to programming and tried to solve this task about deposit calculations but I'm stuck at this for hours. C#

huangapple go评论65阅读模式
英文:

What is the problem with this code? I'm new to programming and tried to solve this task about deposit calculations but I'm stuck at this for hours. C#

问题

using System;

namespace Deposit_calculator
{
    internal class Program
    {
        static void Main(string[] args)
        {
            double depositedsum = double.Parse(Console.ReadLine());
            double depositterm = double.Parse(Console.ReadLine());
            double annualinterestpercentage = double.Parse(Console.ReadLine());
            double sum = depositedsum + depositterm * ((depositedsum * annualinterestpercentage) / 12);
            Console.WriteLine(sum);
        }
    }
}

这是你提供的代码部分。

英文:
using System;

namespace Deposit_calculator
{
    internal class Program
    {
        static void Main(string[] args)
        {
            double depositedsum = double.Parse(Console.ReadLine());
            double depositterm = double.Parse(Console.ReadLine());
            double annualinterestpercentage = double.Parse(Console.ReadLine());
            double sum = depositedsum + depositterm * ((depositedsum * annualinterestpercentage) /  12);
            Console.WriteLine(sum);
            
        }
    }
}

I was supposed to get this answer: 202.85 using this input:200
3
5.7
The formula is: amount = deposited amount + term of the deposit * ((deposited amount * annual interest rate ) / 12)

答案1

得分: 1

根据已经评论的内容 - 百分比应该除以100,即:

using System;

namespace 存款计算器
{
    internal class 程序
    {
        static void (string[] 参数)
        {
            double 存款金额 = double.Parse(Console.ReadLine());
            double 存款期限 = double.Parse(Console.ReadLine());
            double 年利率百分比 = double.Parse(Console.ReadLine()) / 100;
            double 总额 = 存款金额 + 存款期限 * ((存款金额 * 年利率百分比) /  12);
            Console.WriteLine(总额);
        }
    }
}
英文:

As per those that have already commented - percentage should be divided by 100, i.e.:

using System;

namespace Deposit_calculator
{
    internal class Program
    {
        static void Main(string[] args)
        {
            double depositedsum = double.Parse(Console.ReadLine());
            double depositterm = double.Parse(Console.ReadLine());
            double annualinterestpercentage = double.Parse(Console.ReadLine()) / 100;
            double sum = depositedsum + depositterm * ((depositedsum * annualinterestpercentage) /  12);
            Console.WriteLine(sum);
            
        }
    }
}

huangapple
  • 本文由 发表于 2023年6月6日 04:11:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/76409699.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定