ASDV-C-Sharp/MP1/TipTaxTotal_CalebFontenot/Form1.cs

66 lines
1.8 KiB
C#
Executable File

using System.Linq.Expressions;
namespace TipTaxTotal_CalebFontenot
{
public partial class TipTaxTotal : Form
{
public TipTaxTotal()
{
InitializeComponent();
}
private void calculateButton_Click(object sender, EventArgs e)
{
// Setup Vars
double tip;
double salesTax;
double subTotal;
double total;
double salesTaxAmount;
double tipAmount;
try
{
// Get data
tip = double.Parse(tipTextBox.Text);
salesTax = double.Parse(salesTaxTextBox.Text);
subTotal = double.Parse(subTotalTextbox.Text);
// Calculate
// Check if tip is a decimal. If it isn't, turn it into one.
if (tip > .99)
{
while (tip > 1)
{
tip = tip / 10;
}
}
if (salesTax > .99)
{
while (salesTax > 1)
{
salesTax = salesTax / 10;
}
}
tipAmount = subTotal * tip;
salesTaxAmount = subTotal * salesTax;
total = subTotal + (tipAmount + salesTaxAmount);
//Output
outputLabel.Text = "Your total is $" + total;
salesTaxTextBox.Text = salesTax.ToString();
tipTextBox.Text = tip.ToString();
}
catch
{
MessageBox.Show("That's not a number, you doofus!");
}
}
}
}