【问题标题】:Withdrawing money up to a certain amount over the balance of an account从账户余额中提取不超过一定金额的资金
【发布时间】: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


    【解决方案1】:

    我真的不明白你想要在透支箱里放什么,但这里有一些代码可以满足你的其余需求。在此示例中,我使用透支作为帐户透支时要收取的金额。如果这不是您想要的,请澄清。

    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();
                }
            }
    

    【讨论】:

    • 我要做的是在透支文本框中显示剩余透支金额,例如 overdraft.Text = 剩余透支。
    • 所以说一个人只能透支一定数额?说去那里的余额是通过透支金额吗?如果他们确实显示他们还剩下多少?
    • 这对您有帮助吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-08
    • 1970-01-01
    • 1970-01-01
    • 2021-11-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多