提取超过账户余额一定数额的资金
Withdrawing money up to a certain amount over the balance of an account
我正在尝试创建简单的 if 语句,其中程序将检查帐户余额以及它是否低于提款金额。如果是这样,用户将能够提取不超过透支金额的金额。如果金额不大于透支金额,则在透支文本框中显示剩余透支金额。然后在文本框中显示余额。但是,我遇到的问题是,当用户退出时,文本框中的透支不会改变。当客户提款超过余额时,应从透支金额中减去超出的金额。剩余透支应显示在透支 textbox.For 示例中,如果一个人的余额为 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;
}
}
我不太明白您在透支箱中想要什么,但这里有一些代码可以满足您的其余需求。在此示例中,我使用透支作为您在帐户透支时要收取的金额。如果这不是您想要的,请澄清。
private void button_Click(object sender, RoutedEventArgs e)
{
double balance = double.Parse(Balance.Text);
double withdraw = double.Parse(Withdraw.Text);
double overdraft = double.Parse(Overdraft.Text);
if(balance < withdraw)
{
balance -= (overdraft + withdraw);
Balance.Text = balance.ToString();
}
else if(balance > withdraw)
{
balance -= withdraw;
Balance.Text = balance.ToString();
}
}
按下按钮后,更新后的余额会显示在余额文本框中。
编辑:
private void button_Click(object sender, RoutedEventArgs e)
{
double balance = double.Parse(Balance.Text);
double withdraw = double.Parse(Withdraw.Text);
double overdraft = double.Parse(Overdraft.Text);
if (balance < withdraw && (balance - withdraw) >= -(overdraft))
{
balance -= withdraw;
overdraft = overdraft + balance;
Balance.Text = balance.ToString();
Overdraft.Text = overdraft.ToString();
}
}
我正在尝试创建简单的 if 语句,其中程序将检查帐户余额以及它是否低于提款金额。如果是这样,用户将能够提取不超过透支金额的金额。如果金额不大于透支金额,则在透支文本框中显示剩余透支金额。然后在文本框中显示余额。但是,我遇到的问题是,当用户退出时,文本框中的透支不会改变。当客户提款超过余额时,应从透支金额中减去超出的金额。剩余透支应显示在透支 textbox.For 示例中,如果一个人的余额为 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;
}
}
我不太明白您在透支箱中想要什么,但这里有一些代码可以满足您的其余需求。在此示例中,我使用透支作为您在帐户透支时要收取的金额。如果这不是您想要的,请澄清。
private void button_Click(object sender, RoutedEventArgs e)
{
double balance = double.Parse(Balance.Text);
double withdraw = double.Parse(Withdraw.Text);
double overdraft = double.Parse(Overdraft.Text);
if(balance < withdraw)
{
balance -= (overdraft + withdraw);
Balance.Text = balance.ToString();
}
else if(balance > withdraw)
{
balance -= withdraw;
Balance.Text = balance.ToString();
}
}
按下按钮后,更新后的余额会显示在余额文本框中。
编辑:
private void button_Click(object sender, RoutedEventArgs e)
{
double balance = double.Parse(Balance.Text);
double withdraw = double.Parse(Withdraw.Text);
double overdraft = double.Parse(Overdraft.Text);
if (balance < withdraw && (balance - withdraw) >= -(overdraft))
{
balance -= withdraw;
overdraft = overdraft + balance;
Balance.Text = balance.ToString();
Overdraft.Text = overdraft.ToString();
}
}