the problem I am doing in c ++, it is quite simple and it is the following.
Read a value of floating point with two decimal places. This represents a monetary value. After this, calculate the smallest possible number of notes and coins on which the value can be decomposed. The considered notes are of 100, 50, 20, 10, 5, 2. The possible coins are of 1, 0.50, 0.25, 0.10, 0.05 and 0.01. Print the message “NOTAS:” followed by the list of notes and the message “MOEDAS:” followed by the list of coins.
input: 576.73
My 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
desired 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
My code:
#include<bits/stdc++.h>
using namespace std;
int main()
{
int j;
double money;
int tickets[] = {100, 50, 20, 10, 5, 2};
double coins[] = {1.00, 0.50, 0.25, 0.10, 0.05, 0.01};
cin >> money;
cout << "NOTAS:\n";
for(int i = 0; i < 6; i++)
{
j = 0;
while(tickets[i] * j <= money)
j += 1;
money -= tickets[i] * (j - 1);
cout << j - 1 << " nota(s) de R$ " << tickets[i] << ".00\n";
}
cout << "MOEDAS:\n";
for(int i = 0; i < 6; i++)
{
j = 0;
while(coins[i] * j <= money)
j += 1;
money -= coins[i] * (j - 1);
cout << j - 1 << " moeda(s) de R$ " << fixed << setprecision(2) << coins[i] << "\n";
}
}
I also tried it with the tickets double vector but even so, the judge does not accept my answer, so I changed it and it also tells me wrong answer.
Link https://www.urionlinejudge.com.br/judge/en/problems/view/1021
and the screenshot: