|
Hi, so I'm having trouble with my coding. I've already figured out for to take money from Tom and Rob, but i can't figure out how to deposit that value into the bank. here's what i have so far.
I would really appreciate it if, someone would take a look.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Lab05_E00995877
{
public partial class Form1 : Form
{
//Add your form1 variables
Person Tom;
Person Rob;
decimal bank = 50M;
public Form1()
{
InitializeComponent();
//Initialize (create) Tom and Rob
Tom = new Person();
Tom.Name = "Joe";
Tom.Cash = 150M;
btnGetOne.Text = "Get from " + Tom.Name;
Rob = new Person();
Rob.Name = "Bob";
Rob.Cash = 200M;
btnGetTwo.Text = "Get from " + Rob.Name;
UpdateForm();
}
public void UpdateForm()
{
lblFirstName.Text = Tom.Name;
lblMoneyOne.Text = Tom.Cash.ToString();
lblSecondName.Text = Rob.Name;
lblMoneyTwo.Text = Rob.Cash.ToString();
lblMoneyBank.Text = bank.ToString();
}
private void btnGetOne_Click(object sender, EventArgs e)
{
decimal decAmount, decTomAmount, decRobAmount, decBankAmount;
try
{
decAmount = Decimal.Parse(txtMoney.Text);
decTomAmount = Decimal.Parse(lblMoneyOne.Text);
decRobAmount = Decimal.Parse(lblMoneyTwo.Text);
decBankAmount = Decimal.Parse(lblMoneyBank.Text);
//bankamount (bank) Amount punched in (decAmount)
if (decTomAmount >= decAmount)
{
decTomAmount -= decAmount;
lblMoneyOne.Text = Tom.ReceiveCash(decAmount).ToString();
lblMoneyBank.Text = bank.ToString();
//What do i put here to add to bank after subtracting from Tom?
UpdateForm();
}
else
{
MessageBox.Show("Tom doesnt have this many!");
}
txtMoney.Clear();
txtMoney.Focus();
}
catch
{
MessageBox.Show("Please enter numbers only!");
txtMoney.Clear();
txtMoney.Focus();
}
}
private void btnGetTwo_Click(object sender, EventArgs e)
{
decimal decAmount, decTomAmount, decRobAmount;
try
{
decAmount = Decimal.Parse(txtMoney.Text);
decTomAmount = Decimal.Parse(lblMoneyOne.Text);
decRobAmount = Decimal.Parse(lblMoneyTwo.Text);
//bankamount (bank) Amount punched in (decAmount)
if (decRobAmount >= decAmount)
{
decRobAmount -= decAmount;
lblMoneyTwo.Text = Rob.ReceiveCash(decAmount).ToString();
lblMoneyBank.Text = bank.ToString();
//What do i put here to add to bank after subtracting from Rob?
UpdateForm();
}
else
{
MessageBox.Show("Rob doesnt have this many!");
}
txtMoney.Clear();
txtMoney.Focus();
}
catch
{
MessageBox.Show("Please enter numbers only!");
txtMoney.Clear();
txtMoney.Focus();
}
}
}
}
This is the other part defining the class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Lab05_E00995877
{
class Person
{
public string Name;
public decimal Cash;
public decimal GiveCash;
public decimal ReceiveCash(decimal amount)
{
if (amount > 0)
{
Cash -= amount;
return Cash;
}
else
{
MessageBox.Show(amount + " isnt an amount I'll take",
Name + " says..");
return 0;
}
}
}
}
modified 21-Feb-13 0:20am.
|
|
|
|
|
Jimmy1734 wrote: //What do i put here to add to bank after subtracting from Tom?
bank += decAmount; ..but then again, how would you track that it's Toms' money? How much of those 50M belongs to Tom, and how much belongs to Rob?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|