为什么我收到错误“方法'计算收益'没有重载需要 0 个参数”

本文关键字:重载 参数 计算 错误 为什么 方法 收益 | 更新日期: 2023-09-27 18:31:56

这是我的代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Exercise8
{
    class Program
    {
        static void Main(string[] args)
        {
            //declare variables
            int casesSold;
            int costPerCase = 5; //Each case costs the Computer Club $5
            int numBars = 12; //There are 12 candy bars in each case
            double salePrice;
            double forSGA = .9; //The Student Government Association (SGA) will collect 10% of the earnings that the Computer Club makes
            string aCasesSold;
            string aSalePrice;
            //ask user for information
            Console.WriteLine("Please enter how many cases were sold:  ");
            aCasesSold = Console.ReadLine();
            Console.WriteLine("Please enter the sale price per candy bar: ");
            aSalePrice = Console.ReadLine();
            //Convert ints to strings so that they can be a part of the calculations
            casesSold = int.Parse(aCasesSold);
            salePrice = double.Parse(aSalePrice);
            //calculate total cost for the Computer Club
            public static double CalculateTotalCost(double totalCost, int costPerCase, int casesSold)
            {
               totalCost = costPerCase * casesSold;
               return totalCost; 
            }
            //calculate earnings for the Computer Club
            public static double CalculateEarnings(int numBars, int casesSold, double earnings, double salePrice)
            {
                earnings = numBars * salePrice * casesSold;
                return earnings;
            }
            //calculate proceeds
            public static double CalculateProceeds(double proceeds, double forSGA, double earnings, double totalCost)
            {
                proceeds = (forSGA * earnings) - totalCost;
                return proceeds;
            }
            //output proceeds to user
            public static void Output()
            {
                Console.WriteLine("The proceeds for the Computer Club are: {0;C}", CalculateProceeds());
            }
    }
}

由于某种原因,我收到以下两个错误:

salePrice = double.Parse(aSalePrice);末尾的"} 预期"

"方法'计算收益'没有重载需要 0 个参数"

我不知道如何让控制台写我的结局部分,你能帮我吗?我也不确定为什么Visual Studio认为我需要在salePrice = double.Parse(aSalePrice);末尾添加一个"}"

提前感谢您的所有帮助!

为什么我收到错误“方法'计算收益'没有重载需要 0 个参数”

计算收益的方法签名接受 4 个参数

public static double CalculateProceeds(double proceeds, double forSGA, double earnings, double totalCost)

但是您尝试调用它而不将这些参数中的任何一个传递到方法中

Console.WriteLine("The proceeds for the Computer Club are: {0;C}", CalculateProceeds());

此外,您在主方法中声明方法不起作用。

您缺少main方法的结束},并且对CalculateProceeds()的调用缺少其参数。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Exercise8
{
    class Program
    {
        static void Main(string[] args)
        {    
            //declare variables    
            int casesSold;
            int costPerCase = 5; //Each case costs the Computer Club $5
            int numBars = 12; //There are 12 candy bars in each case
            double salePrice;
            double forSGA = .9; //The Student Government Association (SGA) will collect 10% of the earnings that the Computer Club makes
            string aCasesSold;
            string aSalePrice;
            //ask user for information    
            Console.WriteLine("Please enter how many cases were sold:  ");
            aCasesSold = Console.ReadLine();
            Console.WriteLine("Please enter the sale price per candy bar: ");
            aSalePrice = Console.ReadLine();
            //Convert ints to strings so that they can be a part of the calculations    
            casesSold = int.Parse(aCasesSold);
            salePrice = double.Parse(aSalePrice);
        } // was missing.
        //calculate total cost for the Computer Club                
        public static double CalculateTotalCost(double totalCost, int costPerCase, int casesSold)    
        {
           totalCost = costPerCase * casesSold;
           return totalCost;     
        }
        //calculate earnings for the Computer Club    
        public static double CalculateEarnings(int numBars, int casesSold, double earnings, double salePrice)    
        {    
            earnings = numBars * salePrice * casesSold;
            return earnings;    
        }
        //calculate proceeds    
        public static double CalculateProceeds(double proceeds, double forSGA, double earnings, double totalCost)    
        {    
            proceeds = (forSGA * earnings) - totalCost;
            return proceeds;    
        }
        //output proceeds to user    
        public static void Output()    
        {    
            Console.WriteLine("The proceeds for the Computer Club are: {0;C}", CalculateProceeds(0.0, 0.0, 0.0, 0.0));    
        }
    }
}