- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Program to find the Discount Percentage in C++
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
#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
Advertisements