如何检查我的方法是否正确? [英] How do I check if my method is correct?

查看:73
本文介绍了如何检查我的方法是否正确?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须编写一个ComputeSalesTax()方法来接收销售额和税率,并计算并按以下格式显示销售税'100.00的税率为10%是10.00'。



我尝试了什么:



这就是我所得到的:



I have to write a ComputeSalesTax() method that receives a sales amount and a tax rate, and calculates and it displays the sales tax in the following format 'The tax on 100.00 at 10% is 10.00'.

What I have tried:

This is what I got:

using System;
class Program
{
    static void ComputeSalesTax(double saleAmount, double taxRate, double tax)
    {
        saleAmount = 100;
        taxRate = 10;
        tax = taxRate * saleAmount; 
        Console.WriteLine("The tax on {0} at {1} is {2}",
        saleAmount.ToString("C"),
        taxRate.ToString("P"), tax.ToString("F"));
    }
}





我不确定我是否正确,因为我似乎得到以下内容错误:



错误CS5001:程序不包含适用于入口点的静态主方法。



I'm not sure if I'm correct because I seem to get the following error:

Error CS5001: Program does not contain a static 'Main' method suitable for an entry point.

推荐答案

每个C#应用程序.EXE文件都必须包含一个入口点 - 当您尝试运行应用程序时,它就是应用程序开始执行的位置。没有那个入口点,它不是一个EXE文件(虽然它仍然可以是一个程序集,但暂时不要担心 - 你以后会得到它)



你需要一个名为 Main 的方法的入口点可以调用你的新函数。哦,顺便说一下 - 你的作业需要两个参数,而不是三个!

Every C# application .EXE file must contain an entry point - it's where the application begins executing when you try to run it. Without that entry point, it's not a EXE file (though it can still be an Assembly, but don't worry about that for the moment - you'll get to it later)

The entry point you need it a method called Main which can call your new function. Oh, and by the way - your homework calls for two parameters, not three!
using System;

namespace GeneralTestingConsole
    {
    class Program
        {
        public static void Main()
            {
            ComputeSalesTax(100.0, 10.0);
            ComputeSalesTax(100.0, 17.5);
            }
        static void ComputeSalesTax(double saleAmount, double taxRate)
            {
            double tax = taxRate * saleAmount;
            Console.WriteLine("The tax on {0} at {1} is {2}",
                              saleAmount.ToString("C"),
                              taxRate.ToString("P"), tax.ToString("F"));
            }
        }
    }


这篇关于如何检查我的方法是否正确?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆