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.
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));
}
}
}
Comments
Leave a comment