C# 控制台应用程序 - 佣金计算器 - 如何将变量传递到 Main()

标签 c# console-application

我不知道如何将 total、sale 和 comm 传递给 Main()。

有人知道如何将这些变量放入 Main 并在那里显示(输出)它们的名称吗?

现在我可以在 calcComm 中输出变量 ...

提前致谢

菲利普

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication38
{
class Program
{

    public static void getsales()
    {
        string inputsales;
        double total = 0;
        double sale = 0;

        for (int salecount = 1; salecount <= 3; ++salecount)
        {

            Console.WriteLine("Enter sale: ");
            inputsales = Console.ReadLine();
            sale = Convert.ToDouble(inputsales);
            total = total + sale;

        }

        calcComm(total);

    }

    public static void calcComm(double total)
    {

        double comm = 0;
        comm = total * 0.2;
        Console.WriteLine(comm);

    }


    public static void Main () 
    {
        Console.WriteLine("           Sunshine Hot Tubs \n        Sales Commissions Report\n");
        char Letter;

        const string name1 = "Andreas";
        const string name2 = "Brittany";
        const string name3 = "Eric";
        string inputLetter;
        string name;
        Console.WriteLine("Please enter intial or type 'z' to quit");

        inputLetter = Console.ReadLine();
        Letter = Convert.ToChar(inputLetter);



        while (Letter != 'z')
        {

            if (Letter == 'a')
            {
                name = name1;
                getsales();
            }
            else if (Letter == 'b')
            {
                name = name2;
                getsales();
            }
            else if (Letter == 'e')
            {
                name = name3;
                getsales();
            }

                   else
                   {
                      Console.WriteLine("Invalid entry try again");
                   }



                   Console.WriteLine("Please enter intial or type z to quit");

                   inputLetter = Console.ReadLine();
                   Letter = Convert.ToChar(inputLetter);




        }
    }
 }
}

最佳答案

这给出了一个与命令行参数对应的字符串数组。

Main(string [] args)

顺便说一句,在处理货币单位时,最好使用小数而不是 double 。

关于C# 控制台应用程序 - 佣金计算器 - 如何将变量传递到 Main(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10491780/

相关文章:

c# - 无法从 WPF 中的集合绑定(bind)模型的 DependcyProperty

c# - 学习 Objective C 时需要了解的关键事项?

c# - 使用 C# serial.write 拉取任何 Arduino 引脚

C# 将图像数据转换为字节数组

c# - 如何将系统货币符号获取到字符串

C# SendInput() 在控制台应用程序中始终返回 0

html - 如何将控制台应用程序(如 MSBuild 或 PowerShell)的彩色输出转换为保留颜色的 HTML 格式?

c# - Web API 中的最佳/安全字符串长度

C# 控制台应用程序 - 在运行时编辑用户设置

C# 控制台应用 + 事件处理