如何将baseprice变量调用到我想要使用的两个方法。 [英] How do I call the baseprice variable to the two methods I want to use.

查看:102
本文介绍了如何将baseprice变量调用到我想要使用的两个方法。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

double Tip_One = 1.15;
            double Tip_Two = 1.20;
            const double Sales_Tax = 1.09;
            double basePrice;
            


            Console.WriteLine(" Enter the base Price of your meal");

            basePrice = Convert.ToDouble(Console.ReadLine());
            Console.WriteLine(" The total price of your meal is {0}", calculateprice1(A));
            Console.WriteLine(" The total price of your meak is {0}", calculateprice2(B));

                
        }

            public static double calculateprice(double A)
            {
                double A;
                A = baseprice * salestax * tipone;
                return A;
            }
        public static double calculateprice2(double B)
        {
            double B;
            B = baseprice * salestax * tiptwo;
            return B;
        }

推荐答案

我不知道如何为每种方法调用baseprice变量,所以我可以使用公式得到baseprice的输出乘以销售税和每个小费百分比。



简单:

"I don't know how to call the baseprice variable to each method so I can use the formula to get the output of the baseprice multiplied by the sales tax and each tip percentage."

Easy:
basePrice = Convert.ToDouble(Console.ReadLine());
Console.WriteLine(" The total price of your meal is {0}", calculateprice1(basePrice));
Console.WriteLine(" The total price of your meal is {0}", calculateprice2(basePrice));



但是......你需要使用这些参数,而不是掩盖它们:


But... you need to use the parameters, not mask them:

public static double calculateprice(double baseprice)
    {
    return  baseprice * salestax * tipone;
    }
public static double calculateprice2(double baseprice)
    {
    return baseprice * salestax * tiptwo;
    }


这篇关于如何将baseprice变量调用到我想要使用的两个方法。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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