0

this simple program is to calculate how many banknotes and coins i created BNC function with two parameters the first the reminded money and the second is the paper/coin value and with every calculation there is 0.01 from money is missing idk why

#include <iostream>

using namespace std;

float BNC(float &monex, float value) {
    float amount = 0;
    while (monex >= value){
        monex -= value;
        amount += 1;
    }
    return amount;
}

int main()
{
    float x;
    cin >> x;
    cout << "NOTAS:" << endl;
    cout << BNC(x, 100) << " nota(s) de R$ 100.00" << endl;
    cout << BNC(x, 50) << " nota(s) de R$ 50.00" << endl;
    cout << x << endl;
    cout << BNC(x, 20) << " nota(s) de R$ 20.00" << endl;
    cout << BNC(x, 10) << " nota(s) de R$ 10.00" << endl;
    cout << BNC(x, 5) << " nota(s) de R$ 5.00" << endl;
    cout << BNC(x, 2) << " nota(s) de R$ 2.00" << endl;
    cout << "MOEDAS:" << endl;
    cout << BNC(x, 1) << " moeda(s) de R$ 1.00" << endl;
    cout << BNC(x, 0.50) << " moeda(s) de R$ 0.50" << endl;
    cout << BNC(x, 0.25) << " moeda(s) de R$ 0.25" << endl;
    cout << BNC(x, 0.10) << " moeda(s) de R$ 0.10" << endl;
    cout << BNC(x, 0.05) << " moeda(s) de R$ 0.05" << endl;
    cout << BNC(x, 0.01) << " moeda(s) de R$ 0.01" << endl;

}
  • 5
    Use integer number of cents, instead of floating point – M.M Jun 21 '20 at 09:24
  • as example i enterd 576.73 and the output was 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 2 moeda(s) de R$ 0.01 ------ it shoud be 3moseda(s) de R$ 0.01 – Yousef Mohamed Jun 21 '20 at 09:25

0 Answers0