0

这是我的代码:

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);

“方法 'CalculateProceeds' 没有重载需要 0 个参数”

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

提前感谢您的所有帮助!

4

2 回答 2

1

您的 CalculateProceeds 方法签名接受 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 方法中声明了不起作用的方法。

于 2013-09-19T16:08:09.537 回答
0

您缺少方法的结束}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));    
        }
    }
}
于 2013-09-19T16:09:02.017 回答