如何修复此代码(我认为是变量)

时间:2019-07-26 19:25:49

标签: c#

我试图让用户输入现金量,然后希望从现金中扣除。

完整代码:https://codeshare.io/5OmLvr

![Image of the variables I want

namespace Gambling
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public static int cash;

        public MainWindow(Button confirmBtn, TextBox numInput, TextBox cashAmt,
            TextBlock cashLbl, bool contentLoaded)
        {
            this.confirmBtn = confirmBtn;
            this.numInput = numInput;
            this.cashAmt = cashAmt;
            this.cashLbl = cashLbl;
            _contentLoaded = contentLoaded;
        }

        public MainWindow()
        {
            InitializeComponent();
            int cash = 1000;
            cashLbl.Text = "Cash £" + cash;
            cashAmt = Console.WriteLine("t;
        }

        private void ConfirmBtn_Click(object sender, RoutedEventArgs e)
        {
            cash =- CashAmt;
            cashLbl.Text = "Cash £" + cash;
        }
    }
}

1 个答案:

答案 0 :(得分:0)

我认为这可能会有所帮助。

    public MainWindow()
    {
        InitializeComponent();
        cash = 1000;
        cashLbl.Text = "Cash £" + cash.ToString();
        cashAmt.Text = "Enter the amount of money";
    }

    private void ConfirmBtn_Click(object sender, RoutedEventArgs e)
    {
        cash -= Convert.ToInt32(cashAmt.Text);
        cashLbl.Text = "Cash £" + cash.ToString();
    }