Untitled
unknown
csharp
a year ago
1.9 kB
4
Indexable
using System;
class Program
{
// dDiscount function to calculate and return discount percent based on quantity and line price
static double Discount(int iQty, double dLinePrice)
{
// Check the conditions for discount
if (dLinePrice > 1000)
{
return 15.0; // 15% discount if line price exceeds 1000
}
else if (dLinePrice > 500 || iQty > 10)
{
return 10.0; // 10% discount if line price exceeds 500 or quantity exceeds 10
}
else
{
return 0.0; // No discount
}
}
// Price function calculates the final discounted price including tax
static double Price(int iQty, double dUnitPrice)
{
const double Tax = 0.25; // Define the tax factor
// Calculate line price
double dLinePrice = iQty * dUnitPrice;
// Call dDiscount function to get the discount percentage
double dDiscPere = Discount(iQty, dLinePrice);
// Calculate discount amount
double dDiscountAmount = dLinePrice * (dDiscPere / 100);
// Calculate net price after discount
double dNetPrice = dLinePrice - dDiscountAmount;
// Apply the tax to the net price
double dFinalPrice = dNetPrice * (1 + Tax);
return dFinalPrice;
}
static void Main(string[] args)
{
// User input for quantity and unit price
Console.Write("Enter the number of units: ");
int iQty = int.Parse(Console.ReadLine());
Console.Write("Enter the unit price: ");
double dUnitPrice = double.Parse(Console.ReadLine());
// Calculate the final price using the Price function
double dFinalPrice = Price(iQty, dUnitPrice);
// Output the final discounted price including tax
Console.WriteLine($"The final price after discount and tax is: {dFinalPrice:C2}");
}
}Editor is loading...
Leave a Comment