Work out how much a pile of coins is worth.
What to build
A program that names its constants and splits a total.
Requirements
- Read the number of 100, 50, 25 and 10 poisha coins.
- Define the four coin values as
const. - Print
T taka P poisha.
Input
One line with four whole numbers.
Output
One line.
Constraints
Each count is from 0 to 1000000.
Example
Input:
1 1 1 1
Output:
1 taka 85 poisha
Why it works
Working entirely in the smallest unit keeps everything in whole numbers, so no rounding errors can creep in.
Examples
Example 1 · Input
1 1 1 1
Expected output
1 taka 85 poisha
Example 2 · Input
2 0 0 0
Expected output
2 taka 0 poisha
Hints
Hint 1
Use const for each coin's value in poisha.
Hint 2
Add everything up in poisha.
Hint 3
Then use / and % by 100 to split it.
Solution
Show one correct solution (try it yourself first)
#include <iostream>
using namespace std;
int main() {
const long long A = 100, B = 50, C = 25, D = 10;
long long a, b, c, d;
cin >> a >> b >> c >> d;
long long total = a * A + b * B + c * C + d * D;
cout << total / 100 << " taka " << total % 100 << " poisha" << endl;
return 0;
}