-
Notifications
You must be signed in to change notification settings - Fork 0
/
Return_Coins.cpp
44 lines (40 loc) · 1.06 KB
/
Return_Coins.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main(){
float change;
do
{
cout << "Amount to be changed(give the input in dollar): ";
cin >> change;
} while (change < 0.01);
int coin1, coin5, coin10, coin25;
coin25= 0;
coin10 = 0;
coin5= 0;
coin1 = 0;
int cents = round(100 * change);
while (cents > 0)
{
if(cents >= 25){
cents = (cents - 25);
coin25++;
}
else if(cents >= 10 && cents < 25){
cents = (cents - 10);
coin10++;
}
else if(cents >= 5 && cents < 10){
cents = (cents - 5);
coin5++;
}
else{
cents = (cents - 1);
coin1++;
}
}
int coin = (coin1 + coin5 + coin10 + coin25);
cout << coin << endl;
//cout << "Change returned " << coin << " coins "<< endl;
//cout<<"Of value "<<coin1<<" penny "<<coin5<<" nickel "<<coin10<<" dime "<<coin25<<" quater"<<endl;
return 0;