- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

In this problem, we are given four numbers that define the totalPrice and the ratio of coins of 1 Rs, 50 paise, 25 paise in the bag. Our task is to create a *program to find the count of coins of each type from the given ratio in C++.*

**Code description** − Here, we need to use the coins of 1 Rs, 50 paise, and 25 paise from the bag to give the total sum of coins to the given total.

**Let’s take an example to understand the problem,**

TotalPrice = 225, 1Rs = 2, 50P = 3, 25P = 4

1 Rs coin = 100 50 P coin = 150 25 P coin = 200

Considering the ratio, the value of coins that make up the value.

1 RE coin 2X, 50 paise coin 1.5X, 25 paise coin 1X,

Summing up all values = 225

2X + 1.5X + 1X = 225 4.5X = 225 => X = 225/4.5 = 50,

Value of 1Re coins = 100, coins 100

Value of 50 paise coins = 75, coins 150

Value of 25 paise coins = 50, coins 200

As in the explanation, we will find the amount contributed by each coin to the sum. And then find the number of coins each value based on the value. For 1 Re coins, X is the number of coins.

For 50 paise coins, 2X is the number of coins.

For 25 paise coins, 4X is the number of coins.

**Program to illustrate the working of our solution,**

#include <iostream> using namespace std; int CalcCoinValue(int totalPrice, int re1, int p50, int p25) { float val1Coin = (re1 * 1.0), val50pCoin = (p50/2.0), val25pCoin =(p25/4.0); int result = totalPrice / (val1Coin + val50pCoin + val25pCoin); return result; } int main() { int totalPrice = 225; int re1 = 2, p50 = 3, p25 = 4; int coinValue = CalcCoinValue(totalPrice, re1, p50, p25); cout<<"Count of 1 rupee coin = " <<(coinValue * re1)<<endl; cout<<"Count of 50 paise coin = " <<(coinValue * p50)<<endl; cout<<"Count of 25 paise coin = " <<(coinValue * p25)<<endl; return 0; }

Count of 1 rupee coin = 100 Count of 50 paise coin = 150 Count of 25 paise coin = 200

- Related Questions & Answers
- C++ program to find the type of the given iterator
- Program to find number of coins needed to make the changes with given set of coins in Python
- Program to find the common ratio of three numbers in C++
- C# program to count the occurrences of each character
- Find coordinates of the triangle given midpoint of each side in C++
- Write a C Program to count the frequency of each character
- Java program to count the occurrences of each character
- C++ program to find the Sum of each Row and each Column of a Matrix
- Count operations of the given type required to reduce N to 0 in C++
- Program to find number of coins needed to make the changes in Python
- Divide the given linked list in two lists of size ratio p:q in C++ Program
- C/C++ Program for Greedy Algorithm to find Minimum number of Coins
- C program to find type of array entered by the user.
- C program to find the median of a given list.
- Find the ordering of tasks from given dependencies in C++

Advertisements