C++ A software company sells a package that retails for $99. Quantity discounts
ID: 3799986 • Letter: C
Question
C++
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%
Write a program that asks for today’s date ( You MUST use cin>>date .Do not use getline(cin, date)), the company name and the quantity they wish to buy and computes the total cost of the purchase. If the user enters a negative value for the quantity, tell him/her “invalid quantity”. If a zero is entered, tell “Hope you decide to buy our software in the future.”
Explanation / Answer
solution--
#include<iostream>
using namespace std;
int main()
{
string date,comp;
int q;
double cost=99;
cout<<"Enter date"<<endl;
cin>>date;
cout<<"Enter the company name"<<endl;
cin>>comp;
cout<<"Enter the quantity you want to buy"<<endl;
cin>>q;
if(q<0)
{
cout<<"invalid quantity"<<endl;
return 0;
}
else if(q==0)
{
cout<<"hope you decide to buy our software in the future"<<endl;
}
else
{
cost=cost*q;
if(q>=10 && q<=19) //20% discount
{
cost=cost-(0.2)*cost;
}
else if(q>=20 && q<=49)
{
cost=cost-(0.3)*cost;
}
else if(q>=50 && q<=99)
{
cost=cost-(0.4)*cost;
}
else if(q>=100)
{
cost=cost-(0.5)*cost;
}
}
cout<<"the total cost is "<<cost<<endl;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.