我很努力地理解函数如何在main之外工作。我只需要计算用户输入的主要信息的总数,但是我应该调用一个函数来总和这个信息。这里是我到目前为止的代码,我相信它是不是很接近正确,在正确的方向轻推将是一个巨大的帮助在c中使用函数#
namespace ConsoleApplication17
{
class Program
{
static void Main(string[] args)
{
string customerName, customerState;
double numberItems, itemPrice;
Console.WriteLine("Please enter the customer name");
customerName = Console.ReadLine();
Console.WriteLine("Please enter the state in which you reside:");
customerState = Console.ReadLine();
Console.WriteLine("How many items were purchased?");
numberItems = int.Parse(Console.ReadLine());
Console.WriteLine("What was the price of said items?");
itemPrice = Convert.ToDouble(Console.ReadLine());
}
public static double ComputeTotal (double total)
{
double totalAmount;
Console.Write(total);
}
}
public static double ComputeTax (double totalAmount, string state, string fl, string nj, string ny)
{
if (state == fl)
return totalAmount*.06;
else if (state == nj)
return totalAmount*.07;
else if (state == ny)
return totalAmount*.04;
}
总之,我需要使用函数ComputeTotal来乘以numberItems和itemPrice
为什么不直接调用'ComputeTotal()'? – Houseman 2015-02-24 02:34:36
我首先将方法的数量和价格传递给方法,进行计算并返回结果。 – 2015-02-24 02:34:50
@GrantWinney所以这里是我想说的话,不要太罗嗦。这是为了上课,我的老师很快就过去了,我不知道如何将这些传递给方法。我一直在看例子,但没有像样的解释,仅靠我自己就很难。 – Wardy24 2015-02-24 02:36:40