Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need Help! For the following code below; it does everything for me except when I put letters for quanity and 3-3 for price. I cannot

Need Help! For the following code below; it does everything for me except when I put letters for quanity and 3-3 for price. I cannot get the output/result that I want. I get an exception error and it closes the code. My code is below. What I'm doing wrong?

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace

{

class Program

{

static void Main(string[] args)

{

int count = 0;

string[,] items = new string[100, 4];

bool repeat = true;

string name;

decimal price, subtotal = 0.0M, tax, total;

int quantity;

Console.Write("\t\t\tScan Items Now");

do

{

for (int i = 0; i

{

Console.Write(" Item Name (enter 0 to stop):\t");

name = Console.ReadLine();

if (name.Trim() == "0")

{

repeat = false;

break;

}

else

{

Console.Write(" Item Price:\t\t\t$");

price = Convert.ToDecimal(Console.ReadLine().Replace('$', ' ').Trim());

Console.Write(" Quantity:\t\t\t");

quantity = Convert.ToInt32(Console.ReadLine());

subtotal = price * quantity;

items[i, 0] = name;

items[i, 1] = price.ToString();

items[i, 2] = quantity.ToString();

items[i, 3] = subtotal.ToString();

count++;

}

}

} while (repeat);

subtotal = 0.0M;

for (int i = 0; i

{

subtotal = subtotal + Convert.ToDecimal(items[i, 3]);

}

tax = subtotal * Convert.ToDecimal(0.065);

total = subtotal + tax;

for (int i = 0; i

{

items[i, 1] = "$" + items[i, 1];

items[i, 3] = "$" + items[i, 3];

}

Console.WriteLine(" \t\t\tYour Receipt ");

Console.WriteLine("Item\t\tPrice\t Quantity\t Subtotal ");

for (int i = 0; i

{

for (int j = 0; j

{

Console.Write("{0,-15}", items[i, j]);

}

Console.WriteLine();

}

Console.WriteLine(" ---------------------------------------------------");

Console.WriteLine(" " + count + " Items.");

Console.WriteLine(" Subtotal:\t\t$" + subtotal.ToString("0.00"));

Console.WriteLine(" Tax(0.065%):\t\t$" + tax.ToString("0.00"));

Console.WriteLine(" Total:\t\t\t$" + total.ToString("0.00"));

Console.WriteLine(" Press any key to exit...");

Console.ReadKey();

}

}

}

image text in transcribedExample

3Fe//F/Courses/CoP2350/ClassWork/Receiptv3 With Validation ExamA/Receiptv2/bin/Debug/Receiptv2 EXE Scan Items Now Item Nane(enter to stop): sdfsadoIU009097 87987jsahdfjshd asdf (small) ab sadf-01.33a sdf+ads99.00 Enter Quantity: fsfdg Enter Quantity (1 or more) sadf333 Enter Quantity (1 or more): Enter Quantity (1 or more) Enter Price: cfb Enter Price (cannot be less than ): 3-3 Enter Price (cannot be less nter Price (cannotbe less than e)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases And Information Systems 1 International Baltic Conference Dbandis 2020 Tallinn Estonia June 19 2020 Proceedings

Authors: Tarmo Robal ,Hele-Mai Haav ,Jaan Penjam ,Raimundas Matulevicius

1st Edition

303057671X, 978-3030576714

More Books

Students also viewed these Databases questions

Question

=+herself to in terms of equity with regard to this assignment?

Answered: 1 week ago

Question

=+ What typical employee will the IA compare him/

Answered: 1 week ago

Question

=+7 What is the overall cost of the international assignment?

Answered: 1 week ago