標籤:nbsp convert nta pos lin str send event false
花了兩個小時理解公式,我數學是不是太弱了..
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 貸款電腦{ public partial class Form1 : Form { int pos = 0; double year, cost, temp;//分別表示 年限 金額 利率 public Form1() { InitializeComponent(); } //pos == 1 表示等額本息 private void checkBox1_CheckedChanged(object sender, EventArgs e) { if(checkBox1.Checked ) { checkBox2.Checked = false; pos = 1; } else pos = 0; } //pos == 2 表示等額本金 private void checkBox2_CheckedChanged(object sender, EventArgs e) { if (checkBox2.Checked) { checkBox1.Checked = false; pos = 1; } else pos = 0; } //計算按鈕 private void button1_Click(object sender, EventArgs e) { try //選擇還款方式 { if ( pos == 0) throw new Exception (); } catch (Exception) { MessageBox.Show("先選擇還款方式才能進行此運算!", "錯誤", MessageBoxButtons.OK); } try //輸入貸款年限 { year = Convert.ToDouble(textBox1.Text); year = year * 12;//轉換成貸款月份 } catch (Exception) { MessageBox.Show("先輸入貸款年限才能進行此運算!", "錯誤", MessageBoxButtons.OK); } try //輸入貸款金額 { cost = Convert.ToDouble(textBox2.Text); cost = cost * 10000;// 貸款金額,單位元 } catch (Exception) { MessageBox.Show("先輸入貸款金額才能進行此運算!", "錯誤", MessageBoxButtons.OK); } try //輸入貸款利率 { temp = Convert.ToDouble(textBox3.Text); temp = temp / 1200;//貸款月利率 } catch (Exception) { MessageBox.Show("先輸入貸款利率才能進行此運算!", "錯誤", MessageBoxButtons.OK); } textBox4.Text = ""; textBox5.Text = ""; textBox6.Text = ""; if (checkBox1.Checked) { double temp1 = cost * temp*Math.Pow(1 + temp, year+1) / (Math.Pow(1+temp,year) -1);//*temp * cost double temp2 = temp1 * year -cost; double temp3 = temp1 * year; textBox4.Text = temp1.ToString(); textBox5.Text = temp2.ToString(); textBox6.Text = temp3.ToString(); } else if(checkBox2.Checked) { double temp1 = ((cost / year + cost * temp) + cost / year * (1 + temp)) / 2 ; //總利息 double temp2 = temp1 * year - cost ; double temp3 = temp1 * year; textBox4.Text = temp1.ToString(); textBox5.Text = temp2.ToString(); textBox6.Text = temp3.ToString(); } } private void button2_Click(object sender, EventArgs e) { try //選擇還款方式 { if (pos == 0) throw new Exception(); } catch (Exception) { MessageBox.Show("先選擇還款方式才能進行此運算!", "錯誤", MessageBoxButtons.OK); } try //輸入貸款年限 { year = Convert.ToDouble(textBox1.Text); year = year * 12;//轉換成貸款月份 } catch (Exception) { MessageBox.Show("先輸入貸款年限才能進行此運算!", "錯誤", MessageBoxButtons.OK); } try //輸入貸款金額 { cost = Convert.ToDouble(textBox2.Text); cost = cost * 10000;// 貸款金額,單位元 } catch (Exception) { MessageBox.Show("先輸入貸款金額才能進行此運算!", "錯誤", MessageBoxButtons.OK); } try //輸入貸款利率 { temp = Convert.ToDouble(textBox3.Text); temp = temp / 1200;//貸款月利率 } catch (Exception) { MessageBox.Show("先輸入貸款利率才能進行此運算!", "錯誤", MessageBoxButtons.OK); } textBox4.Text = ""; textBox5.Text = ""; textBox6.Text = ""; if (checkBox1.Checked) { double temp1 = cost * temp * Math.Pow(1 + temp, year + 1) / (Math.Pow(1 + temp, year) - 1);//*temp * cost double temp2 = temp1 * year - cost; double temp3 = temp1 * year; textBox4.Text = temp1.ToString(); textBox5.Text = temp2.ToString(); textBox6.Text = temp3.ToString(); } else if (checkBox2.Checked) { double temp1 = ((cost / year + cost * temp) + cost / year * (1 + temp)) / 2; //總利息 double temp2 = temp1 * year - cost ; double temp3 = temp1 * year; textBox4.Text = temp1.ToString(); textBox5.Text = temp2.ToString(); textBox6.Text = temp3.ToString(); } } }}
貸款計算機C#實現 課程作業一