static void Main(string[] args) { const double PRICE_PER_BLENDER = 39.95; const double SALES_TAX = 0.07; string name, address, city, state; int zipCode, blenders; double totalPrice, tax, due; Console.Write("Enter your name: "); name = Console.ReadLine(); Console.Write("Street address: "); address = Console.ReadLine(); Console.Write("City: "); city = Console.ReadLine(); Console.Write("State: "); state = Console.ReadLine(); Console.Write("Zip code: "); zipCode = Convert.ToInt32(Console.ReadLine()); Console.Write("How many blenders do you want to order? "); blenders = Convert.ToInt32(Console.ReadLine()); totalPrice = blenders * PRICE_PER_BLENDER; tax = totalPrice * SALES_TAX; due = totalPrice + tax; Console.WriteLine(); Console.WriteLine("Receipt for: "); Console.WriteLine(name); Console.WriteLine(address); Console.WriteLine("{0}, {1} {2}", city, state, zipCode); Console.WriteLine(); Console.WriteLine("{0} blenders ordered at {1} each", blenders, PRICE_PER_BLENDER.ToString("C")); Console.WriteLine(); Console.WriteLine("Total: {0, 10}", totalPrice.ToString("C")); Console.WriteLine("Tax: {0, 10}", tax.ToString("C")); Console.WriteLine("-----------------------"); Console.WriteLine("Due: {0, 10}", due.ToString("C")); }
private void generateReceiptButton_Click(object sender, EventArgs e) { const double SALES_TAX = 0.07; const double PRICE_PER_BLENDER = 39.95; double amountDue, netDue, tax; string name = nameTextBox.Text; string address = addressTextBox.Text; string city = cityTextBox.Text; string state = stateTextBox.Text; int zipCode = Convert.ToInt32(zipCodeTextBox.Text); int blenders = Convert.ToInt32(blenderQuantityTextBox.Text); amountDue = blenders * PRICE_PER_BLENDER; tax = amountDue * SALES_TAX; netDue = amountDue + tax; outputLabel.Text = String.Format("Receipt for\n"); outputLabel.Text += String.Format("{0}\n", name); outputLabel.Text += String.Format("{0}\n", address); outputLabel.Text += String.Format("{0}, {1} {2}\n\n", city, state, zipCode); outputLabel.Text += String.Format("{0} blenders ordered at {1} each\n\n", blenders, PRICE_PER_BLENDER.ToString("C")); outputLabel.Text += String.Format("Total: {0,10}\n", amountDue.ToString("C")); outputLabel.Text += String.Format("Tax: {0,10}\n", tax.ToString("C")); outputLabel.Text += String.Format("-----------------------------\n"); outputLabel.Text += String.Format("Due: {0,10}\n", netDue.ToString("C")); }