【问题标题】:No overload for method 'DisplayOutput' takes 0 arguments方法“DisplayOutput”没有重载需要 0 个参数
【发布时间】:2013-10-15 18:53:23
【问题描述】:

我正在尝试编写一个简单的程序来计算员工的净工资。据我所知,除了对 DisplayOutput(); 的方法调用之外,我的代码是可靠的。 我理解错误的含义,但我不明白如何修复它以进行编译。

这是我的代码:

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

namespace Project02CoddR
{
    class NetPayApp
    {
        static void Main(string[] args)
        {
            Console.BackgroundColor = ConsoleColor.White;
            Console.ForegroundColor = ConsoleColor.Black;
            Console.Clear();
            DisplayTitle();
            InputData();
            DisplayOutput();
            TerminateProgram();

        }

        public static void DisplayTitle()
        {

            Console.WriteLine();
            Console.Write("\tProject 02 - Net Pay Calculator - ");
            Console.WriteLine();
            DrawLine();

        }

        public static void InputData()
        {
            Console.WriteLine();
            Console.Write("Please enter the number of hours worked this week: ");
            int hoursWorked = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine();
            Console.Write("Please enter your hourly rate of pay <e.g. 9.35>: ");
            double payRate = Convert.ToDouble(Console.ReadLine());
            Console.WriteLine();
            Console.Write("Please enter your number of dependants: ");
            int dependants = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine();
            Console.Write("\n\tAre you a salesperson? <Y or N>: ");
            string aValue = Console.ReadLine();

        }

        public static int InputSales(string aValue)
        {
            int sales = -1;
            if (aValue == "Y" || aValue == "y" || aValue == "Yes" || aValue == "yes")
            {
                Console.Write("Please enter your sales amount for this period: ");
                sales = Convert.ToInt32(Console.ReadLine());
            }
            else if (aValue == "N" || aValue == "n" || aValue == "No" || aValue == "no")
            {
                sales = -1;
            }
            return sales;

        }

        public static double CalculatePay(int hoursWorked, double payRate, int sales)
        {
            double grossPay = hoursWorked * payRate;
            if (sales >= 0)
            {
                grossPay = grossPay +(.02*sales);
            }
            else if (hoursWorked > 40)
            {
                grossPay = grossPay + (.5*payRate) * (hoursWorked-40);
            }
            return grossPay;

        }

        public static double CalculateTax(int dependants, double grossPay)
        {
            int cutOff = 100 + (100 * dependants);
            double taxes;
            if (grossPay <= cutOff)
            {
                taxes = .15 * grossPay;
            }
            else
            {
                taxes = .15 * cutOff + .25*(grossPay-cutOff);
            }
            return taxes;
        }

        public static void DisplayOutput(double grossPay, double taxes)
        {
            double netPay = grossPay - taxes;
            Console.WriteLine();
            Console.WriteLine("Gross Pay: ".PadLeft(30, ' ') + grossPay);
            Console.WriteLine("Taxes: ".PadLeft(30, ' ') + taxes);
            Console.WriteLine("Net Pay: ".PadLeft(30, ' ') + netPay);
            Console.WriteLine();
            DrawLine();
        }

        public static void DrawLine()
        {
            Console.Write("______________________________________________");
        }

        public static void TerminateProgram()
        {
            Console.Write("Press any key to terminate the program...");
            Console.Read();
        }

    }
}

【问题讨论】:

    标签: c# methods call


    【解决方案1】:

    DisplayOutput 需要将要显示的值传递给它;例如:

        static void Main(string[] args)
        {
            Console.BackgroundColor = ConsoleColor.White;
            Console.ForegroundColor = ConsoleColor.Black;
            Console.Clear();
            DisplayTitle();
            InputData();
            DisplayOutput(CalculatePay(40, 50, 60), CalculateTax(4, CalculatePay(40, 50, 60)));
            TerminateProgram();
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多