Hi am quite new to visual studios.
This is my code so far to make an example of an atm, i have a text box and i put an amount in and then i have this button where i clic
The problem is that the value in textboxamount.Text
contains something that can't be converted to a double.
The best way to handle this is to use double.TryParse
instead:
private void buttoncredit_Click(object sender, RoutedEventArgs e)
{
double newAmount;
if(!double.TryParse(textboxamount.Text, out newAmount))
{
// The input is wrong - handle that
MessageBox.Show("Please enter a valid amount");
textboxamount.Focus();
return;
}
totalamount += newAmount;
balance1 = "Your Balance is: £";
label2.Content = balance1 + totalamount;
// .. Your code...