0

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:

enter image description here

link to problem:

https://www.urionlinejudge.com.br/judge/en/problems/view/1021

The differences: n

jodidos.com
  • 43
  • 1
  • 7
  • 6
    Can you be more specific with your issue? – drum May 12 '21 at 04:06
  • 2
    Without knowing the specifications for the problem you're solving it's impossible to know what might be incorrect. Can't say if your output is correct or not without knowing what correct looks like. – Retired Ninja May 12 '21 at 04:13
  • The problem is basically that my exits work out well, but Uri does not accept it, and I want to know where I am wrong @drum – jodidos.com May 12 '21 at 04:13
  • 3
    Unless you can clarify what the problem is in more technical terms, we're left guessing what it is. – tadman May 12 '21 at 04:15
  • It is on the page of the Uri Judge problem 1021, with the same name as the title of the question @RetiredNinja – jodidos.com May 12 '21 at 04:17
  • Sorry not to add the details – jodidos.com May 12 '21 at 04:25
  • 1
    Does the judge tell you _why_ it's being rejected? Incorrect output? Time limit exceeded? If the output is incorrect, this _might_ be an ["is floating point math broken?"](https://stackoverflow.com/questions/588004/is-floating-point-math-broken) issue occurring in the test cases you aren't privy to. Since you know the format of the input, you could read it as a string, parse it to an integer number of cents, and do arithmetic on that. – Nathan Pierson May 12 '21 at 04:28
  • It only tells me Wrong answer (100%), and no, I have no problems with decimals as I already mentioned, I also have no problems with the time limit, you can test the program yourself, and the answers are correct @NathanPierson – jodidos.com May 12 '21 at 04:47
  • 1
    You have sound reasons to assume that the online judge is broken. Complain about that to the site. What can we do for you? – Yunnosch May 12 '21 at 06:27
  • 1
    I think your output is incorrect for 999999.99. That does not explain why the judge tells you that 100% of your answers are incorrect. So it is still appearing to be broken. Your program, but also the judge. Complain there. Your program could probably be fixed by heeding the recommendation (among others by @NathanPierson) to not use floating point variables to store currency values. Currency is always integer. There are no half-pennies or millicents. – Yunnosch May 12 '21 at 06:36
  • I've had online judges reject working solutions because of a missing or extra newline at the end. Might try not printing one on the last line. – Retired Ninja May 12 '21 at 08:56
  • @Yunnosch You are right, I fixed it, however it is still not accepted, I will upload the capture of the differences that the page provided me – jodidos.com May 12 '21 at 13:08
  • It looks like they don't actually want the `NOTAS:` and `MOEDAS:` lines despite having them in the example output. Try removing those statements and seeing if that matches the format they're actually seeking. – Nathan Pierson May 12 '21 at 15:40
  • @NathanPierson Even so I get the same result, and the same difference, remove "Notes:" and "M" – jodidos.com May 12 '21 at 19:08
  • Well the judge is not broken. My solution got accepted. – risingStark May 13 '21 at 14:23

0 Answers0