Question: I am writing a console application in C#. It is a receipt where the user inputs the item then quantity and then price per item.
I am writing a console application in C#. It is a receipt where the user inputs the item then quantity and then price per item. It is then validated through regular expressions. I need to put this in a multidimensional array to print out (command line print), like each row would have a columns for item, quantity, price and then subtotal for each item, but cannot figure it out. I also need the regular expression in a do while loop so when zero is entered alone it would end the user input but i am not sure if i should put that in the regular expression for item?? and start the array print out of the user input "receipt" with totals and then a final calculation of all subtotals added together with tax and total. i have this so far:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Text.RegularExpressions;
namespace Exam4 { class Program { static void Main(string[] args) { do { Regex reciept = new Regex(@"[a-zA-Z0-9 \(\)\&\+\-\.\_ "); string itemName;
Console.WriteLine("Please Enter Item:"); itemName = Console.ReadLine();
while (reciept.Match(itemName).Success == false) { Console.WriteLine("Invalid Entry"); Console.WriteLine("Enter Item: "); itemName = Console.ReadLine(); } if (reciept.Match(itemName).Success == true) { Regex quant = new Regex(@"^[0-9]$"); string quantity; Console.WriteLine("Please Enter Quantity: "); quantity = Console.ReadLine();
while (quant.Match(quantity).Success == false) { Console.WriteLine("Invalid Entry"); Console.WriteLine("Enter Quantity"); quantity = Console.ReadLine(); } if (reciept.Match(quantity).Success == true) ; { Regex price = new Regex(@"^[0-9\.]$"); string itemPrice; Console.WriteLine("Enter Price"); itemPrice = Console.ReadLine();
while (price.Match(itemPrice).Success == false) { Console.WriteLine("Invalid Entry (only digits and . allowed"); Console.WriteLine("Enter Price: "); itemPrice = Console.ReadLine(); }
} } } while ( != 0);
} } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
