【程式設計-C#】電費計算器(非時間電價,非營業用)
-
台電 - 電價表
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { double D = Convert.ToDouble(textBox1.Text); //將輸入的度數字串轉成浮點數double double MS = 0, MW = 0; //MS夏日電費, MW非夏日電費; int L120 = 120, L330 = 330, L500 = 500, L700 = 700, L1000 = 1000; double s163 = 1.63, s238 = 2.38, s352 = 3.52, s461 = 4.61, s542 = 5.42, s613 = 6.13; //夏日費率 double w163 = 1.63, w210 = 2.10, w289 = 2.89, w379 = 3.79, w442 = 4.42, w483 = 4.83; //非夏日費率 //計算夏日電費 if (D <= L120) MS = D * s163; else if (D <= L330) MS = L120 * s163 + (D - L120) * s238 ; else if (D <= L500) MS = L120 * s163 + (L330 - L120) * s238 + (D - L330) * s352; else if (D <= L700) MS = L120 * s163 + (L330 - L120) * s238 + (L500 - L330) * s352 + (D - L500) * s461; else if (D <= L1000) MS = L120 * s163 + (L330 - L120) * s238 + (L500 - L330) * s352 + (L700 - L500) * s461 + (D - L700) * s542; else MS = L120 * s163 + (L330 - L120) * s238 + (L500 - L330) * s352 + (L700 - L500) * s461 + (L700 - L1000) * s542 + (D - L1000) * s613; ; //計算非夏日電費 if (D <= L120) MW = D * w163; else if (D <= L330) MW = L120 * w163 + (D - L120) * w210; else if (D <= L500) MW = L120 * w163 + (L330 - L120) * w210 + (D - L330) * w289; else if (D <= L700) MW = L120 * w163 + (L330 - L120) * w210 + (L500 - L330) * w289 + (D - L500) * w379; else if (D <= L1000) MW = L120 * w163 + (L330 - L120) * w210 + (L500 - L330) * w289 + (L700 - L500) * w379 + (D - L700) * w442; else MW = L120 * w163 + (L330 - L120) * w210 + (L500 - L330) * w289 + (L700 - L500) * w379 + (L700 - L1000) * w442 + (D - L1000) * w483; ; if (radioButton1.Checked) label4.Text = MS.ToString(); else label4.Text = MW.ToString(); } private void S2NS(object sender, EventArgs e) //2個RadioBuuton 的 共同 Click事件函式 { RadioButton rb = (RadioButton)sender; if (rb.Checked) button1_Click(rb, e); } } }