Write a C++ program that asks for the number of units sold and computes the total cost of the purchase.

Write a C++ program that asks for the number of units sold and computes the total cost of the purchase.

Write a C++ program that asks for the number of units sold and computes the total cost of the purchase.

Object:

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 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. C++ Projects.

Code:

#include<iostream>
#include<conio.h>

using namespace std;
void main()
{
double cost, qunt;
cout<<“\n\t**************************************************************************************\n”;
cout<<“\t\t:S o f t w a r e c o m p a n y sells a p a c k a g e:\n”;
cout<<“\t**************************************************************************************\n\n”;

cout<<“Enter here how many unit sold : “;
cin>>qunt;
if(qunt >0 && qunt <10)
{
cost=qunt*99;
cout<<“\nTotal cost of the purchase is : $”<<cost<<endl;
}
else if(qunt >=10 && qunt <=19)
{
cost=qunt*99*0.2;
cout<<“\nTotal cost of the purchase is : $”<<cost<<endl;
}
else if(qunt >=20 && qunt <=49)
{
cost=qunt*99*0.3;
cout<<“\nTotal cost of the purchase is : $”<<cost<<endl;
}
else if(qunt >=50 && qunt <=99)
{
cost=qunt*99*0.4;
cout<<“\nTotal cost of the purchase is : $”<<cost<<endl;
}
else if(qunt > 100)
{
cost=qunt*99*0.5;
cout<<“\nTotal cost of the purchase is : $”<<cost<<endl;
}
else
{
cout<<“\nInvalid Input!!! Please Enter Greater than 0…”;
}
getch();

}

#include<iostream>
#include<conio.h>

using namespace std;
void main()
{
	double cost, qunt;
	cout<<"\n\t**************************************************************************************\n";
	cout<<"\t\t:S o f t w a r e    c o m p a n y    sells    a    p a c k a g e:\n";
	cout<<"\t**************************************************************************************\n\n";

	cout<<"Enter here how many unit sold : ";
	cin>>qunt;
	if(qunt >0 && qunt <10)
	{
		cost=qunt*99;
		cout<<"\nTotal cost of the purchase is : $"<<cost<<endl;
	}
	else if(qunt >=10 && qunt <=19)
	{
		cost=qunt*99*0.2;
		cout<<"\nTotal cost of the purchase is : $"<<cost<<endl;
	}
	else if(qunt >=20 && qunt <=49)
	{
		cost=qunt*99*0.3;
		cout<<"\nTotal cost of the purchase is : $"<<cost<<endl;
	}
	else if(qunt >=50 && qunt <=99)
	{
		cost=qunt*99*0.4;
		cout<<"\nTotal cost of the purchase is : $"<<cost<<endl;
	}
	else if(qunt > 100)
	{
		cost=qunt*99*0.5;
		cout<<"\nTotal cost of the purchase is : $"<<cost<<endl;
	}
	else
	{
		cout<<"\nInvalid Input!!! Please Enter Greater than 0...";
	}
	getch();

}

Output:

Write a C++ program that asks for the number of units sold and computes the total cost of the purchase.

Another Program: Write a program that asks the user to enter a number of seconds.

3 thoughts on “Write a C++ program that asks for the number of units sold and computes the total cost of the purchase.”

  1. Pingback: Write a C++ program to check triangle by entering 3 angles

  2. Pingback: C++ projects for beginners with source code - Codeboks

  3. Your program says it gives the total cost of the purchase. In reality it gives you the total savings of the discount. Other than that it works great.

Leave a Comment

Your email address will not be published. Required fields are marked *