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

Respuesta :

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;

[tex]i f (cost > 1000)[/tex] {        [tex]discount=cost * 0.10[/tex];        }

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

   return 0;

}

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

[tex]i f (cost > 1000)[/tex] {        [tex]discount=cost * 0.10[/tex];        }

This prints the cost

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