39.3k views
2 votes
A shop will give discount of 10% if the cost of purchased quantity is more than 1000. Ask user for quantity suppose, one unit will cost 100. Judge and print total cost for user. Plz give answer in C++.

User Aztek
by
5.0k points

1 Answer

3 votes

Answer:

The program in C++ is as follows:

#include <iostream>

using namespace std;

int main(){

int qty;

float discount = 0;

cout<<"Quantity: ";

cin>>qty;

int cost = qty * 100;


i f (cost > 1000) {
discount=cost * 0.10; }

cout<<"Cost: "<<cost - discount;

return 0;

}

Step-by-step explanation:

This declares the quantity as integer

int qty;

This declares and initializes discount to 0

float discount = 0;

This prompts the user for quantity

cout<<"Quantity: ";

This gets input for quantity

cin>>qty;

This calculates the cost

int cost = qty * 100;

If cost is above 1000, a discount of 10% is calculated


i f (cost > 1000) {
discount=cost * 0.10; }

This prints the cost

cout<<"Cost: "<<cost - discount;

User Dsdel
by
5.5k points