如何将局部变量价值(销售和佣金)带入主要方法?
我必须创建两种方法来完成该程序。第一种方法通过用户输入收集销售额并将值返回给 main。第二种方法计算佣金并返回最终佣金。我们必须在计划结束时计算佣金。
namespace Lab_4
{
internal class Program
{
static double GetSales()
{
Console.WriteLine("Enter your sales");
double sales = Convert.ToDouble(Console.ReadLine());
return sales;
}
static double GetCommission(double sales)
{
if (sales >= 0 && sales <=999)
{
double commission = sales * 0.03;
return commission;
}
else
{
if (sales >= 1000 && sales <= 2999)
{
double commission = sales * 0.04;
return commission;
}
else
{
if (sales >= 3000)
{
double commission = sales * 0.05;
return commission;
}
else
{
return 0;
}
}
}
}
static void Main(string[] args)
{
GetSales();
GetCommission();
}
}
}
我根本不知道如何正确地做到这一点。如何从局部变量的销售和佣金中提取值?第一种方法效果很好。但第二个没有读取销售价值。
I have to create 2 methods to complete the program. First method collects the sales via user input and returns value to main. Second methods calculates the commission and returns the final commission. We have to calculate the commission at the end of the program.
namespace Lab_4
{
internal class Program
{
static double GetSales()
{
Console.WriteLine("Enter your sales");
double sales = Convert.ToDouble(Console.ReadLine());
return sales;
}
static double GetCommission(double sales)
{
if (sales >= 0 && sales <=999)
{
double commission = sales * 0.03;
return commission;
}
else
{
if (sales >= 1000 && sales <= 2999)
{
double commission = sales * 0.04;
return commission;
}
else
{
if (sales >= 3000)
{
double commission = sales * 0.05;
return commission;
}
else
{
return 0;
}
}
}
}
static void Main(string[] args)
{
GetSales();
GetCommission();
}
}
}
I simply can't figure out how to do this correctly. How do extract the values from sales and commissions which are local variables? The first method works fine. But the 2nd one doesn't read the sales value.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于您要返回
GetSales
和GetCommission
的值,因此您可以通过将结果分配给变量来存储结果:然后您可以将这些变量用于您的核心内容。
Since you're returning the values of
GetSales
andGetCommission
, you can store the results by assigning them to a variable:Which you can then use those variables to your heart content.