如果公里超过 100 公里,每公里额外支付 0.20 美分
If Kilometer above 100 kilometer, pay 0.20 cent extra per kilometer
如果公里超过 100 公里,则总价需要每增加 1 公里增加 0.20 美分。我该怎么做呢?我不知道。我使用 Windows 表格 Visual Studio 2019。我有一些东西,但还不完整。总价还应包括每公里0.20美分。
private void button1_Click(object sender, EventArgs e)
{
string typeCar = comboBox1.Text;
int car= 0;
int days = int.Parse(textBox1.Text);
int totalKM = int.Parse(textBox2.Text);
if (typeCar == "A")
{
car= 50;
}
else if (typeCar == "B")
{
car = 75;
}
else
{
car = 100;
}
MessageBox.Show("De totale prijs wordt " + car * days + " euro");
}
我建议您将总价存储在一个单独的变量中。这样,您可以检查 totalKM
值并在这种情况下添加到总价:
decimal totalPrice = car * days;
if (totalKM > 100)
{
totalPrice += totalKM * .2;
}
MessageBox.Show("De totale prijs wordt " + totalPrice + " euro");
private void button1_Click(object sender, EventArgs e)
{
int days = int.Parse(textBox1.Text);
int totalKM = int.Parse(textBox2.Text);
string typeCar = comboBox1.Text;
(string,decimal)[] priceTable = {("A", 50.0m),("B",75.0m),(typeCar, 100.0m)};
decimal price = priceTable.First(p => p.Item1 == typeCar).Item2;
price = price * days + (totalKM>100?(totalKM-100)*0.2m:0);
MessageBox.Show($"De totale prijs wordt {price:N2} euro");
}
在这里查看它的工作原理:
如果公里超过 100 公里,则总价需要每增加 1 公里增加 0.20 美分。我该怎么做呢?我不知道。我使用 Windows 表格 Visual Studio 2019。我有一些东西,但还不完整。总价还应包括每公里0.20美分。
private void button1_Click(object sender, EventArgs e)
{
string typeCar = comboBox1.Text;
int car= 0;
int days = int.Parse(textBox1.Text);
int totalKM = int.Parse(textBox2.Text);
if (typeCar == "A")
{
car= 50;
}
else if (typeCar == "B")
{
car = 75;
}
else
{
car = 100;
}
MessageBox.Show("De totale prijs wordt " + car * days + " euro");
}
我建议您将总价存储在一个单独的变量中。这样,您可以检查 totalKM
值并在这种情况下添加到总价:
decimal totalPrice = car * days;
if (totalKM > 100)
{
totalPrice += totalKM * .2;
}
MessageBox.Show("De totale prijs wordt " + totalPrice + " euro");
private void button1_Click(object sender, EventArgs e)
{
int days = int.Parse(textBox1.Text);
int totalKM = int.Parse(textBox2.Text);
string typeCar = comboBox1.Text;
(string,decimal)[] priceTable = {("A", 50.0m),("B",75.0m),(typeCar, 100.0m)};
decimal price = priceTable.First(p => p.Item1 == typeCar).Item2;
price = price * days + (totalKM>100?(totalKM-100)*0.2m:0);
MessageBox.Show($"De totale prijs wordt {price:N2} euro");
}
在这里查看它的工作原理: