I have a problem but I don't understand what it is, since I did the tests on my own and it shows me the results correctly, very small and large, I also have no problems with subtraction with decimals. Could you tell me where I'm failing, so I can fix it?
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
double notes[] = { 100, 50, 20, 10, 5, 2, 1, 0.5, 0.25, 0.10, 0.05, 0.01 };
int my_notes[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
bool coins = true;
int i = 0;
double money;
cin >> money;
money *= 100; // To avoid subtraction of decimals
cout << fixed << setprecision( 2 );
cout << "NOTAS:" << endl;
while ( i < 12 ) {
if ( money - ( notes[ i ] * 100 ) >= 0.00 ) {
money -= ( notes[ i ] * 100 );
my_notes[ i ] += 1;
} else {
if ( i < 6 ) {
cout << my_notes[ i ] << " nota(s) de R$ " << notes[ i ] << endl;
}
else {
if ( coins ) {
cout << "MOEDAS:" << endl;
coins = false;
}
cout << my_notes[ i ] << " moeda(s) de R$ " << notes[ i ] << endl;
}
i += 1;
}
}
return 0;
}
Input:
888.88
Output:
NOTAS:
8 nota(s) de R$ 100.00
1 nota(s) de R$ 50.00
1 nota(s) de R$ 20.00
1 nota(s) de R$ 10.00
1 nota(s) de R$ 5.00
1 nota(s) de R$ 2.00
MOEDAS:
1 moeda(s) de R$ 1.00
1 moeda(s) de R$ 0.50
1 moeda(s) de R$ 0.25
1 moeda(s) de R$ 0.10
0 moeda(s) de R$ 0.05
3 moeda(s) de R$ 0.01
Input:
576.73
Output:
NOTAS:
5 nota(s) de R$ 100.00
1 nota(s) de R$ 50.00
1 nota(s) de R$ 20.00
0 nota(s) de R$ 10.00
1 nota(s) de R$ 5.00
0 nota(s) de R$ 2.00
MOEDAS:
1 moeda(s) de R$ 1.00
1 moeda(s) de R$ 0.50
0 moeda(s) de R$ 0.25
2 moeda(s) de R$ 0.10
0 moeda(s) de R$ 0.05
3 moeda(s) de R$ 0.01
Capture the desired output:
link to problem:
https://www.urionlinejudge.com.br/judge/en/problems/view/1021