Program to find the Discount Percentage in C++

C++Server Side ProgrammingProgramming

In this problem, we are given two numbers that define the marked price(M) and selling price(S) of a certain product. Our task is to create a program to find the Discount Percentage in C++.

Discount is the amount that is deducted from the actual price (marked price) on a product.

The formula for discount is,

discount = marked price - selling price

Discount percentage is the percentage of the price that is deducted from the actual price of the product.

The formula for discount percentage is,

discount percentage = (discount / marked price ) * 100

Let’s take an example to understand the problem,

Input

240, 180

Output

25%

Explanation

Discount = (240 - 180) = 60
Discount percentage = (60/240)*100 = 25%

Solution Approach

The formulas for discount and discount percentage are −

Discount = marked price - selling price
Discount percentage = (discount / marked price ) * 100

Program to illustrate the working of our solution,

Example

 Live Demo

#include <iostream>
using namespace std;
int main() {
   float MP = 130, SP = 120;
   float DP = (float)(((MP - SP) * 100) / MP);
   printf("The discount percentage on the given product is %.2f\n", DP);
   return 0;
}

Output

The discount percentage on the given product is 7.69
raja
Published on 02-Jun-2020 11:45:46
Advertisements