Question
CAN U FIX MY CODE? HERE'S THE QUESTION. Write a program to process items that a user purchases. i. We like to be able to
CAN U FIX MY CODE?
HERE'S THE QUESTION.
Write a program to process items that a user purchases. i. We like to be able to have the user enter prices for as many items that she wants to purchase. Allow for a sentinel value to end the input loop. ii. Do not allow the user to enter an invalid price (A number greater than 1000). Issue an error message and allow the user to enter a valid price. iii. Calculate and display the total amount of all purchases and the number of items purchased. iv. Calculate and display the total amount with an applied 8% tax rate. v. Calculate and display the average price of all purchases after the application of tax.
HERE'S THE MAIN OF THE CODE:
//variable definitions double price; double total = 0; double totalCount = 0; double total_incTax = 0; double average = 0; while(true){ System.out.println("Enter the price of the item or -1 to quit"); price = input.nextDouble(); total = total + price; totalCount = totalCount +1; total_incTax = total + (0.08 *total); average = total / totalCount; if(price == -1){ break; } if (price <= 1000) { System.out.println("Total price is" + total); System.out.println("Total price including tax is" + total_incTax); System.out.println("average is" + average); price++; } else{ System.out.println("Invalid price. Please enter a valid price"); THE CODE CALCULATES THE TOTAL AND AVERAGE FOR EVERY SINGLE NUMBER ENTERED. INSTEAD OF CALCULATING FOR ALL OF IT??
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