using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication19 { class Program { public static void Main() { string name = ""; int itemQuantity = 0; double itemPrice = 0.0; string state = ""; double total = 0.0; name = PromptAndInput("Enter the name of the customer: "); state = PromptAndInput("In which state (NY / NJ / FL) ? "); if (state != "NJ" & state != "nj" & state != "NY" & state != "ny" & state != "FL" & state != "fl") { Console.WriteLine("Error"); while (state != "NJ" & state != "nj" & state != "NY" & state != "ny" & state != "FL" & state != "fl") { state = PromptAndInput("In which state (NY / NJ / FL) ? "); } } itemQuantity = int.Parse(PromptAndInput("How many items were purchased?: ")); if (itemQuantity < 0) Console.WriteLine("Error"); while (itemQuantity < 0) itemQuantity = int.Parse(PromptAndInput("How many items were purchased?: ")); itemPrice = double.Parse(PromptAndInput("What was the unit price of the items?: ")); if (itemPrice < 0) Console.WriteLine("Error"); while (itemPrice < 0) itemPrice = double.Parse(PromptAndInput("What was the unit price of the items?: ")); computeTotal(itemQuantity, itemPrice, total, name); computeTax(state, total, itemQuantity, itemPrice); } public static string PromptAndInput(string prompt) { string userInput; Console.Write(prompt); userInput = Console.ReadLine(); return userInput; } public static object computeTotal(int itemQuantity, double itemPrice, double total, string name) { total = itemQuantity * itemPrice; Console.WriteLine(); Console.WriteLine("--------------------------------------------------"); Console.WriteLine("The total sales for " + name + " are: " + total); return total; } public static object computeTax(string state, double total, int itemQuantity, double itemPrice) { double taxAmt = 0.0; double totalSales = 0.0; double tax = 0.0; total = itemQuantity * itemPrice; if (state == "NJ" | state == "nj") { tax = 0.07; } else if (state == "NY" | state == "ny") { tax = 0.04; } else if (state == "FL" | state == "fl") { tax = 0.06; } taxAmt = total * tax; totalSales = total + taxAmt; Console.WriteLine("The tax amount is " + taxAmt + " based on a tax rate of: " + tax); Console.WriteLine("The total with taxes is: " + totalSales); Console.WriteLine("--------------------------------------------------"); return totalSales; } } }
TryParse
Double
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)