建立一個計算商務旅行津貼的計算機,讓使用者輸入汽車里程表的起始讀值與結束讀值。根據這兩個讀值,它會計算出使用者駕駛了多少英哩數,並根據公司每英哩補貼0.39美元的政策,計算出要補貼他多少錢。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication3
{
public partial class Form1 : Form
{
int startingMileage;
int endingMileage;
double milesTraveled;
double reimburseRate = .39;
double amountOwed;
public Form1()
{
InitializeComponent();
}
private void numericUpDown1_ValueChanged(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
startingMileage = (int)numericUpDown1.Value;
endingMileage = (int)numericUpDown2.Value;
if (startingMileage <= endingMileage)
{
milesTraveled = endingMileage - startingMileage;
amountOwed = milesTraveled * reimburseRate;
label4.Text = "$" + amountOwed;
}
else
{
MessageBox.Show("The starting mileage must be less than the ending mileage" + " Cannot Calculate Mileage");
}
}
private void numericUpDown2_ValueChanged(object sender, EventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
MessageBox.Show(milesTraveled.ToString());
}
}
}
沒有留言:
張貼留言