Answer to Question #216793 in C# for Phamela

Question #216793

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-13T13:36:25-0400
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;


namespace Q216793
{
    class Program{
        static void Main(string[] args){
            double amount = 0.0;
            double price=0;
            int numberItemsBought=0;
            //prompt the user for the price of an item, until a valid number (between 0 and 150) is entered. 
            while (price >= 0 && price <= 150){
                Console.Write("Enter the price of an item (-1 to stop): ");
                double.TryParse(Console.ReadLine(), out price);
                if(price >= 0 && price <= 150) {
                    amount += price;
                    numberItemsBought++;
                }
            }
            Console.WriteLine("\nThe number of items bought by the customer : {0}", numberItemsBought);
            Console.WriteLine("The total amount due by the customer : ${0}", amount.ToString("N2"));
            //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.
            if (numberItemsBought >= 10)
            {
                Console.WriteLine("The customer qualifies for the free item.");
            }
            Console.ReadLine();
        }
    }
}




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
New on Blog
APPROVED BY CLIENTS