// Program gets a quanity ordered from user
// then determines price and discount based on quantity
// price per item before discounts is $6.00
// order 15 or more, get a 20% discount
// order 10 to 14 - get a 14% discount
// order 5 to 9, get a 10% discount
using System;
class DebugSeven3
{
static void Main()
{
int quantity;
double price;
quantity = GetQuantity();
price = CalculatePrice(quantity);
Console.WriteLine("Final price for {0} items is {1}.",
quantity, price.ToString("c"));
}
private static GetQuantity()
{
int quan;
Console.Write("Enter number of items >> ");
quan = Convert.ToInt32(Console.ReadLine());
}
private CalculatePrice(int quantityOrdered)
{
double PRICE_PER_ITEM = 6.00;
double price = 0;
double discount = 0;
int[] quanLimits = {0, 5, 10, 15;
double[] limits = {0, 0.10, 0.14, 0.20;
for(int x = limits.Length - 1; x >= 0; --x)
if(quantityOrdered >= limits[x])
discount = limits[x];
x = 0;
price = quantityOrdered * PRICE_PER_ITEM;
price = price - price * discount;
return price;
}
}
pleace help in executing program
Loading
VulpesPosted Oct 9, 2014, 10:25 AM
pad padPosted Oct 9, 2014, 9:57 AM
Posted Oct 9, 2014, 5:23 AM
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Price of a item is $6.00");
int[] discountRangeLimit = { 1, 5, 10, 15 };
double[] discount = { 0, 0.1, 0.14, 0.20 };
Console.Write("How many quanity you need = ");
int numOfItems = Convert.ToInt32(Console.ReadLine());
int sub = 3;
while (sub >= 0 && numOfItems < discountRangeLimit[sub])
--sub;
double customerDiscount = discount[sub] * 100;
Console.WriteLine("Your Discount = {0}%", customerDiscount);
double price = 6 * numOfItems - (customerDiscount / 100);
Console.WriteLine("Total price = {0}", price.ToString("C"));
Console.ReadKey();
}
}
Munesh SharmaPosted Oct 9, 2014, 4:30 AM
using System;
class DebugSeven3
{
static void Main()
{
int quantity;
double price;
quantity = GetQuantity();
price = CalculatePrice(quantity);
Console.WriteLine("Final price for {0} items is {1}.",
quantity, price.ToString("c"));
}
private static GetQuantity()
{
double quan;// before u was using int quan
Console.Write("Enter number of items >> ");
quan = Convert.ToInt32(Console.ReadLine());
}
private CalculatePrice(int quantityOrdered)
{
double PRICE_PER_ITEM = 6.00;
double price = 0;
double discount = 0;
int[] quanLimits = {0, 5, 10, 15;
double[] limits = {0, 0.10, 0.14, 0.20;
for(int x = limits.Length - 1; x >= 0; --x)
if(quantityOrdered >= limits[x])
discount = limits[x];
x = 0;
price = quantityOrdered * PRICE_PER_ITEM;
price = price - price * discount;
return price;
}
}
you cant do like this
int a = convert.toint32(s);
means upper value to lower value