a software company sells a package that retails for $99. quantity discounts are
ID: 3670555 • Letter: A
Question
a software company sells a package that retails for $99.
quantity discounts are given according to the following table: quantity discount
10-19 20%
20-49 30%
50-99 40%
100 or more 50%
create an appliccation that lets the user enter the number of packages purchased. the program should thenm display the amount of the discount(if any) and the total amount of the purchase after the discount.
C# Important Part ""Windows Form application"
I have two buttons(calculateButton and exitButton) and a TextBox(quantityTextBox) for inserting the quantity.
Need to have a MessageBox to pop up with info,
I Have this much
using System;
using System.Windows.Forms;
namespace EE.WinForms
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void btnCalculate_Click(object sender, EventArgs e)
{
try
{
int packagesPurchased = 0;
int.TryParse(txtPackagesPurchased.Text, out packagesPurchased);
if (packagesPurchased > 0)
{
decimal totalWithoutDiscount = 99 * packagesPurchased;
int discountPercentage = ReturnDiscount(packagesPurchased);
txtDiscountPercentage.Text = string.Format("{0}%", discountPercentage);
decimal totalWithDiscount = totalWithoutDiscount * ((decimal) discountPercentage / 100);
txtTotalWithDiscount.Text = string.Format("{0:C}", totalWithDiscount);
}
else
{
MessageBox.Show("You need to purchase more than 0 packages", "Purchasing Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
catch (Exception ex)
{
}
}
private int ReturnDiscount(int packagesPurchased)
{
int discount = 0;
if (packagesPurchased >= 100)
{
discount = 50;
}
else if (packagesPurchased >= 50)
{
discount = 40;
}
else if (packagesPurchased >= 20)
{
discount = 30;
}
else if (packagesPurchased >= 10)
{
discount = 20;
}
return discount;
}
}
}
Can't Figure out how to
How do you show the price after discount, the the total discount, and the percent bracket the purchase falls into in a MessageBox?
Explanation / Answer
First replace following line:
1. decimal totalWithDiscount = totalWithoutDiscount * ((decimal) discountPercentage / 100);
with
2. decimal totalWithDiscount = totalWithoutDiscount * ((100 - (decimal) discountPercentage) / 100);
Line 1 calculates How much discount you are giving not total after deducting discount.
Remove following lines:
txtDiscountPercentage.Text = string.Format("{0}%", discountPercentage);
txtTotalWithDiscount.Text = string.Format("{0:C}", totalWithDiscount);
And create a single string such as
message = "Discount Percentage: " + discountPercentage + "Total after discount: " + totalWithDiscount
show this message in message box. I believe you can do that! :). Else don't hesitate to ask in comments.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.