A software company sells a package that re discounts are given according to the followi A software company sells a package that retails for $99. Quantity discoun according to the following table. Quantity Discount
![Bb https://bb-morte
A software company sells a package that retails for $99. Quantity
discounts are given according to the following table.
A software company sells a package that retails for $99. Quantity discounts are given
according to the following table.
Quantity
Discount
10-19
20-49
20%
30%
50-99
100 or more
40%
50%
Write a program that asks for the number of units sold and computes the total cost of
the purchase.
Input Validation: Make sure the number of units is greater than 0.
Sample Output1:
stv
888 F4
23
2$
%
&
2
3
4
5
6.
8
9
Q
E
R
T
Y
A
S
F
G
H
K
C
V
alt
ion
command
command
..](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fb0702d3c-fe90-41c1-a1a8-2b7e9423c062%2Fc822a2de-915b-4f1e-a581-d301477a49a9%2F59w6hib_processed.jpeg&w=3840&q=75)
![Upload Assignment: Homework .
Sample Output1:
HOMEWORK#4 PART 1
How many units were sold? 0
Units sold must be greater than zero.
Programmer: insert your name here
Sample Output2:
HOMEWORK#4 PART 1
How many units were sold? 57
The total cost of the purchase is $3385.80
Programmer: insert your name here
24
dtv
888
* ES
F1
F3
F4
4)
F9
#3
2$
%
&
*
2
3
4
5
6.
7
8
Q
R
Y
U
A
S
D
F
K
C
V
alt
B
EI](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fb0702d3c-fe90-41c1-a1a8-2b7e9423c062%2Fc822a2de-915b-4f1e-a581-d301477a49a9%2Fp1vh2s2_processed.jpeg&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
GIVEN:
Write a program to compute the total cost of a purchase after applying discounts.
NOTE: As the programming language is not mentioned, we have executed it in C++.
PROGRAM:
#include <iostream>
using namespace std;
int main()
{
//Initialize the variables
float Initial_cost, discount, total_cost;
int unit;
//Get the number of units from user
cout<<"How many units were sold : ";
cin>>unit;
//When unit is zero, print that the units must be greater than 0
if (unit==0)
{
cout<<"Units sold must be greater than 0";
}
else
{
//cost of one unit is $99
//So, Initial cost= number of units * 99
Initial_cost= unit * 99;
//when number of units is between 10 and 19, discount is 20%
if (unit >= 10 && unit <=19 )
{
discount=0.20;
total_cost= Initial_cost - (Initial_cost * discount);
}
//when number of units is between 20 and 49, discount is 30%
else if (unit >= 20 && unit <=49 )
{
discount=0.30;
total_cost= Initial_cost - (Initial_cost * discount);
}
//when number of units is between 50 and 99, discount is 40%
else if (unit >= 50 && unit <=99 )
{
discount=0.40;
total_cost= Initial_cost - (Initial_cost * discount);
}
//when number of units is greater than and equal to 100, discount is 50%
else if (unit >= 100 )
{
discount=0.50;
total_cost= Initial_cost - (Initial_cost * discount);
}
cout<<"The total cost of the purchase is $"<<total_cost;
}
return 0;
}
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 3 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Concepts of Database Management](https://www.bartleby.com/isbn_cover_images/9781337093422/9781337093422_smallCoverImage.gif)
![Prelude to Programming](https://www.bartleby.com/isbn_cover_images/9780133750423/9780133750423_smallCoverImage.jpg)
![Sc Business Data Communications and Networking, T…](https://www.bartleby.com/isbn_cover_images/9781119368830/9781119368830_smallCoverImage.gif)