JunkieHF

Simple Snack Machine Coded in C#

Dec 16th, 2014
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.96 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. namespace Snack_Machine
  12. {
  13.     public partial class frmSnackMachine : Form
  14.     {
  15.         double price = 0.00;
  16.         public frmSnackMachine()
  17.         {
  18.             InitializeComponent();
  19.         }
  20.  
  21.         private void btnChips_Click(object sender, EventArgs e)
  22.         {
  23.             price = price + 0.50;
  24.             lblMoneyOwed.Text = price.ToString();
  25.  
  26.         }
  27.  
  28.         private void btnSourCandy_Click(object sender, EventArgs e)
  29.         {
  30.             price = price + 0.75;
  31.             lblMoneyOwed.Text = price.ToString();
  32.         }
  33.  
  34.         private void btnChocolate_Click(object sender, EventArgs e)
  35.         {
  36.             price = price + 1.00;
  37.             lblMoneyOwed.Text = price.ToString();
  38.         }
  39.  
  40.         private void btnClearChoices_Click(object sender, EventArgs e)
  41.         {
  42.             price = 0.00;
  43.             lblMoneyOwed.Text = price.ToString();
  44.         }
  45.  
  46.         private void btnInsertMoney_Click(object sender, EventArgs e)
  47.         {
  48.             double givenAmount = double.Parse(txtTypeAmount.Text);
  49.             price = price - givenAmount;
  50.             lblMoneyOwed.Text = price.ToString();
  51.             if (givenAmount < price)
  52.                 MessageBox.Show("Please insert more money");
  53.             if (givenAmount >= price)
  54.                 MessageBox.Show("Snack dispensing. Thank you and come again!");
  55.  
  56.         }
  57.  
  58.         private void btnGetChange_Click(object sender, EventArgs e)
  59.         {
  60.             double change = price;
  61.             MessageBox.Show("Change Dispensed");
  62.             price = price - price;
  63.             lblMoneyOwed.Text = price.ToString();
  64.         }
  65.  
  66.         private void btnExit_Click(object sender, EventArgs e)
  67.         {
  68.             this.Close();
  69.         }
  70.     }
  71. }
Add Comment
Please, Sign In to add comment