Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

a software company sells a package that retails for $99. quantity discounts are

ID: 3670392 • 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,

Thank you.

Explanation / Answer

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;
}
}
}