Question
Fix the code using C# below to show : If the user enters a non-numeric input for the price of an item, they should be
Fix the code using C# below to show :
If the user enters a non-numeric input for the price of an item, they should be prompted to re-enter.
If the user enters a negative input for the price of an item, they should be prompted to re-enter.
The rest of the code is working but it prompts a read error when entered a non-numeric input or negative input for the price of an item without prompting to re-enter.
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; do{ Console.WriteLine("What is the amount of item : "); do{ num = double.Parse(Console.ReadLine()); if(num3 && count 6 && count 10 && count hat is the amount of the item? - 10 Do you want to enter more purchases? -Y or N y hat is the amount of the item? - -10 Invalid data entered Please re-enter the amount of the item - n Invalid data entered Please re-enter the amount of the item - h Invalid data entered Please re-enter the amount of the item- 5.0 Do you want to enter more purchases? -Y or N y hat is the amount of the item? -? Do you want to enter more purchases? -Y or N n Sales Receipt Total Purchases: Sales Tax: Number of Items Purchased: Shipping charge: $15.00 $1.50 $5.00 $21.5e rand Total: Hit Enter to exit
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started