Answer to Question #216820 in C# for livy

Question #216820

Write a program that can be used by a vendor of a budget store to calculate and display the number of items bought and the total amount due by a customer (display the total as currency with 2 decimal places). Your program must continuously prompt the user for the price of an item, until a valid number (between 0 and 150) is entered. As you do not know how many items the customer is buying, the vendor must be able to continuously item prices, until he enters a value of -1 to indicate that there are no more item prices to enter.

Customers buying at least 10 items qualify for one free item. When a customer qualifies for the free item, a relevant message must be displayed.

You do not need to create any user defined methods.



1
Expert's answer
2021-07-14T00:49:09-0400
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            double total = 0.0;
            int count = 0 ;
            double price;


            do
            {
                do
                {
                    Console.Write("Enter item price: ");
                    price = Double.Parse(Console.ReadLine());
                } while ((price < 0 || price > 150) && price!=-1.0);
                if (price == 0)
                    Console.WriteLine("Free item has been added");
                if (price >= 0)
                {
                    count++;
                    total += price;
                }
            } while (price >= 0);


            Console.WriteLine();
            Console.WriteLine(String.Format("{0} items bought", count));
            Console.WriteLine(String.Format("total amount due : {0:C2}", total));
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS