Question

I am writing a console application in C#. It is a receipt where the user inputs...

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);


        }
    }
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

using System;
using System.Text.RegularExpressions;
                  
public class Program
{
   public static void Main()
   {
       string itemName;
            do
            {
                Regex reciept = new Regex(@"[a-zA-Z0-9] \\(\\)\\&\\+\\-\\.\\_ ");
              

                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 (itemName!="0");


   }
}

Add a comment
Know the answer?
Add Answer to:
I am writing a console application in C#. It is a receipt where the user inputs...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Fix the code using C# shown below to show the repitition as seen on the example...

    Fix the code using C# shown below to show the repitition as seen on the example screenshot: (Invalid error must repeat): using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Program { class Program { static void Main(string[] args) { double num, count = 0; double Tax = 0.00, ship = 5.00, sum = 0.00; double grandtotal; char line; //Set run =true bool run=true; do { //read amount of item Console.WriteLine("What is the amount of item : "); //read in...

  • So I am creating a 10 question quiz in Microsoft Visual Studio 2017 (C#) and I...

    So I am creating a 10 question quiz in Microsoft Visual Studio 2017 (C#) and I need help editing my code. I want my quiz to clear the screen after each question. It should do one question at a time and then give a retry of each question that was wrong. The right answer should appear if the retry is wrong. After the 1 retry of each question, a grade should appear. Please note and explain the changes you make...

  • CODES: main.cpp #include <iostream> #include <string> #include "ShoppingCart.h" using namespace std; char PrintMenu() { char answer;...

    CODES: main.cpp #include <iostream> #include <string> #include "ShoppingCart.h" using namespace std; char PrintMenu() { char answer; cout << "MENU" << endl; cout << "a - Add item to cart" << endl; cout << "d - Remove item from cart" << endl; cout << "c - Change item quantity" << endl; cout << "i - Output items' descriptions" << endl; cout << "o - Output shopping cart" << endl; cout << "q - Quit" << endl << endl; while (true) {...

  • I need help with the following assignment: Write an application named DailyTemps that continuously prompts a...

    I need help with the following assignment: Write an application named DailyTemps that continuously prompts a user for a series of daily high temperatures until the user enters a sentinel value of 999. Valid temperatures range from -20 through 130 Fahrenheit. When the user enters a valid temperature, add it to a total; when the user enters an invalid temperature, display the error message: Valid temperatures range from -20 to 130. Please reenter temperature. Before the program ends, display the...

  • Need three seperate files. ShoppingCartManager.java ShoppingCart.java ItemsToPurchase.java These are from part 1 what do you mean...

    Need three seperate files. ShoppingCartManager.java ShoppingCart.java ItemsToPurchase.java These are from part 1 what do you mean by deep study 7.25 LAB*: Program: Online shopping cart (Part 2) Note: Creating multiple Scanner objects for the same input stream yields unexpected behavior. Thus, good practice is to use a single Scanner object for reading input from System.in. That Scanner object can be passed as an argument to any methods that read input This program extends the earlier Online shopping cart program (Consider...

  • For the following C# program: Let’s add one more user defined method to the program. This...

    For the following C# program: Let’s add one more user defined method to the program. This method, called ReverseDump is to output the values in the array in revere order (please note that you are NOT to use the Array.Reverse method from the Array class). The approach is quite simple: your ReverseDump method will look very similar to the Dump method with the exception that the for loop will count backwards from num 1 to 0 . The method header...

  • I need help with this assignment, can someone HELP ? This is the assignment: Online shopping...

    I need help with this assignment, can someone HELP ? This is the assignment: Online shopping cart (continued) (C++) This program extends the earlier "Online shopping cart" program. (Consider first saving your earlier program). (1) Extend the ItemToPurchase class per the following specifications: Parameterized constructor to assign item name, item description, item price, and item quantity (default values of 0). (1 pt) Public member functions SetDescription() mutator & GetDescription() accessor (2 pts) PrintItemCost() - Outputs the item name followed by...

  • This program extends the earlier "Online shopping cart" program. (Consider first saving your earlier program).

    Ch 7 Program: Online shopping cart (continued) (Java)This program extends the earlier "Online shopping cart" program. (Consider first saving your earlier program).(1) Extend the ItemToPurchase class per the following specifications:Private fieldsstring itemDescription - Initialized in default constructor to "none"Parameterized constructor to assign item name, item description, item price, and item quantity (default values of 0). (1 pt)Public member methodssetDescription() mutator & getDescription() accessor (2 pts)printItemCost() - Outputs the item name followed by the quantity, price, and subtotalprintItemDescription() - Outputs the...

  • Where in the c# code can i enter the information to print to console?   Console.WriteLine("Pattern found...

    Where in the c# code can i enter the information to print to console?   Console.WriteLine("Pattern found at:{0}", i); Console.WriteLine(pattern) public void preKMP() { int m = pattern.Length; int k; f[0] = -1; for (int i = 1; i < m; i++) { k = f[i - 1]; while (k >= 0) { if (pattern[k] == pattern[i - 1]) break; else k = f[k]; } f[i] = k + 1; } } public int Search() // s is string sequence, pattern...

  • Hello in C#. I need help understanding and knwoing what i missed in my program. The...

    Hello in C#. I need help understanding and knwoing what i missed in my program. The issue is, the program is supposed to have user input for 12 family members and at the end of the 12 it asks for user to input a name to search for. When i put a correct name, it always gives me a relative not found message. WHat did i miss. And can you adjust the new code so im able to see where...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT