C# 我能';I don’我对这个工资代码没有正确的计算方法

C# 我能';I don’我对这个工资代码没有正确的计算方法,c#,C#,我无法正确计算此代码。我试图在14天内每天增加一倍的工资。例如:在第1天,输出应为1;在第2天,输出应为2;第3天的输出应为4;第14天的产量应该是1050 using System; public class Salary { public static void Main(string[] args) { int salary = 1; int w; Console.WriteLine("Enter number of da

我无法正确计算此代码。我试图在14天内每天增加一倍的工资。例如:在第1天,输出应为1;在第2天,输出应为2;第3天的输出应为4;第14天的产量应该是1050

using System;

public class Salary
{
    public static void Main(string[] args)
    {
        int salary = 1;
        int w;

        Console.WriteLine("Enter number of days worked: ");
        w = Convert.ToInt32(Console.ReadLine());

        for (int wage = 1; wage < w + 1; wage++)
        {
            salary = wage * salary;
        }
        Console.WriteLine("The salary is: ${0}.00", salary);
        Console.WriteLine("Press any key to close....");
        Console.ReadKey();

    }
}
使用系统;
公费
{
公共静态void Main(字符串[]args)
{
国际薪金=1;
int w;
Console.WriteLine(“输入工作天数:”);
w=Convert.ToInt32(Console.ReadLine());
对于(整数工资=1;工资
用于(整数工资=0;工资
所以你真正要做的是将薪水乘以2的幂(从0到13)。比如:

public static void Main(string[] args)
{
    int salary = 1;
    int w;

    Console.WriteLine("Enter number of days worked: ");
    w = Convert.ToInt32(Console.ReadLine());

    salary *= Math.Pow(2, Math.Min(w - 1, 13));

    Console.WriteLine("The salary is: ${0}.00", salary);
    Console.WriteLine("Press any key to close....");
    Console.ReadKey();

}

我认为工资不是每天翻倍,而是每天增加基本工资的100%。正如你所说,基本工资是1。第一天是第1天,第二天是第2天,第三天是第3天(如果是双精度,则为4天)。如果我的理解有误,请纠正。根据我的理解,我将您的代码更改为以下

第14天的产量为105.00

publicstaticvoidmain(字符串[]args)
{
国际薪金=1;
int w;
int-amounterned=0;
Console.WriteLine(“输入工作天数:”);
w=Convert.ToInt32(Console.ReadLine());
对于(整数工资=1;工资
VS附带了一个功能强大的调试器。学习它。使用它。喜欢它。你有没有试过调试它,并查看每次迭代的结果?理想情况下,把它写在一张纸上……检查一下
Math.Pow
salaray
看起来有点不对?
*=
运算符优点的绝佳示例;-)他说“例如:第一天的输出应该是1;第二天的输出应该是2;第三天的输出应该是4
public static void Main(string[] args)
{
    int salary = 1;
    int w;

    Console.WriteLine("Enter number of days worked: ");
    w = Convert.ToInt32(Console.ReadLine());

    salary *= Math.Pow(2, Math.Min(w - 1, 13));

    Console.WriteLine("The salary is: ${0}.00", salary);
    Console.WriteLine("Press any key to close....");
    Console.ReadKey();

}
public static void Main(string[] args)
        {
            int salary = 1;
            int w;
            int amountEarned = 0;

            Console.WriteLine("Enter number of days worked: ");
            w = Convert.ToInt32(Console.ReadLine());

            for (int wage = 1; wage < w + 1; wage++)
            {
                var currentDaySalary = (salary * ((wage*100)/100));
                amountEarned += currentDaySalary;
            }
            Console.WriteLine("The salary is: ${0}.00", amountEarned);
            Console.WriteLine("Press any key to close....");
            Console.ReadKey();

        }