Write the following code using c #, Write a method that takes two arguments: a cost price and a two letter province code. It will calculate and display the selling price. (If province is Ontario a tax of 13% is added to the price, if the province is Quebec a tax of 17% is added to the cost price. There is no tax for the rest of the provinces and territories). In your main, call this method enough times to fully test it
时间: 2023-07-02 15:15:20 浏览: 87
c#销售管理系统,有代码
Sure! Here's the C# code for the method you described:
```
public void CalculateSellingPrice(double costPrice, string provinceCode)
{
double sellingPrice = 0.0;
switch (provinceCode.ToUpper())
{
case "ON":
sellingPrice = costPrice * 1.13;
break;
case "QC":
sellingPrice = costPrice * 1.17;
break;
default:
sellingPrice = costPrice;
break;
}
Console.WriteLine($"The selling price for {provinceCode} is {sellingPrice:C}");
}
```
And here's an example of how you could call this method in your `Main` function to test it:
```
static void Main(string[] args)
{
CalculateSellingPrice(100.0, "ON"); // This should output $113.00
CalculateSellingPrice(100.0, "QC"); // This should output $117.00
CalculateSellingPrice(100.0, "BC"); // This should output $100.00
}
```
Hope that helps!
阅读全文