Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/258.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在函数中间使用Ma.PoW_C# - Fatal编程技术网

C# 在函数中间使用Ma.PoW

C# 在函数中间使用Ma.PoW,c#,C#,我正在做一个金融项目,我需要使用math.pow来学习(1+(利率)^学期)。它不喜欢我的格式,但我不知道如何以它喜欢的方式编写它。 以下是我正在进行的完整循环: static void doPV() { double Famount, rate, pv; int term; Famount = getValue("Amount to be recieved in the future? "); rate = getVal

我正在做一个金融项目,我需要使用math.pow来学习(1+(利率)^学期)。它不喜欢我的格式,但我不知道如何以它喜欢的方式编写它。 以下是我正在进行的完整循环:

static void doPV()
    {
        double Famount, rate, pv;
        int term;

        Famount = getValue("Amount to be recieved in the future? ");
        rate = getValue("Annual Interest rate (6.5% = 6.5): ");
        while (rate < 1 || rate > 25)
        {
            Console.WriteLine("Rate must be between 1% and 25%");
            rate = getValue("annual Interest rate (6.5% = 6.5): ");
        }
        term = getTerm();

        pv = 0;
            for(int i=1; i<= term; i++)
        {
            double intearn = (pv = Famount / Math.Pow(1 + (rate / 100.0 / 12.0)), term);
        }
        Console.WriteLine(Famount.ToString("C") +
                          " recieved in " + term.ToString() +
                          " months discounted at an annual rate of " +
                          (rate / 100).ToString("P") + " has a value today of: " +
                          pv.ToString("C"));
    }
double intearn = pv = Famount / Math.Pow(1 + (rate / 100.0 / 12.0), term);
static void doPV()
{
双倍重量、速率、pv;
整数项;
Famount=getValue(“未来收到的金额?”);
利率=getValue(“年利率(6.5%=6.5):”;
而(比率<1 | |比率>25)
{
Console.WriteLine(“费率必须介于1%和25%之间”);
利率=getValue(“年利率(6.5%=6.5):”;
}
term=getTerm();
pv=0;

for(int i=1;i看起来只是括号的位置不正确。应该这样做:

double intearn = pv = Famount / Math.Pow(1 + (rate / 100.0 / 12.0), term);

我发现将这样的语句分成几行有助于可读性

“它不喜欢我的格式”既不是错误消息,也不是对收到的问题的技术描述
-在问题文本中拼写错误,您写道(1+(rate)^term),这与1+(rate^term)相同。但您的代码试图执行(1+速率)^term,这与该文本不同。您想要哪一个?(来自@Gekctek的答案正确地指出了一个括号问题,但保留了此逻辑差异。)谢谢,你说得对。它很好用。我想我需要它在那里,这样它的翻倍才能正确阅读。非常感谢你的帮助。我觉得这么简单的东西很傻。
double intearn = pv = Famount / Math.Pow(1 + (rate / 100.0 / 12.0), term);