【发布时间】:2016-03-17 13:58:22
【问题描述】:
我正在尝试创建简单的 if 语句,其中程序将检查帐户余额以及是否低于提款金额。如果是这样,用户将能够提取高达透支金额的金额。如果金额不大于透支金额,在透支文本框中显示剩余透支金额。然后在文本框中显示余额。但是,我遇到的问题是,当用户退出时,文本框中的透支不会改变。当客户提取的金额超过余额时,应从透支金额中减去他们超出的金额。剩余的透支应该显示在透支文本框中。例如,如果一个人的余额为 0,并且允许透支 50 并尝试透支 20,那么 30 应该仍然剩余并显示在透支文本框中和 -20应显示在余额文本框中。 (如果这是有道理的):D 这是我到目前为止的代码
private void withdraw_Click(object sender, EventArgs e)
{
Ballance = double.Parse(balance.Text);
Withdrawtxt = double.Parse(txt_withdraw.Text);
Overdraftadd = double.Parse(overdraft.Text);
//this checks if the user can even make a withdraw. This checks if the withdraw amount is bigger than ballance + Overdraft
if (Ballance + Overdraftadd >= Withdrawtxt)
{
//if the user can withdraw but its more than the ballance then ballance is equal to ballance + the overdraft: If not then the ballance is equal to ballance - withdraw.
classify = (Ballance < Withdrawtxt) ? Ballance = (Ballance + Overdraftadd) - Withdrawtxt : Ballance = Ballance - Withdrawtxt;
//this is then displayed in the textbox
balance.Text = "" + Ballance;
// here i want to make it so that the overdraft is changed if the user has used some of it. E.G user withdraws but has to use 20 out of 50 overdraft.
// if ? true false statement
classify = (Ballance < Withdrawtxt) ? Overdraftadd = : ;
//display overdraft in this box.
overdraft.Text = "" + Overdraftadd;
}
}
【问题讨论】:
标签: c# visual-studio button textbox display