What's the problem in this code? i am unable to find it out (FLOW005)

my code : https://onlinegdb.com/HkhNGSoAS
problem : https://www.codechef.com/problems/FLOW005

You are not printing a new line.
Add endl or “\n” after cout<<s and your code should work fine.
Program output should strictly match the problem output section.

2 Likes

I spent a lot of time to think about this silly mistake…
thanks.

1 Like

@aditigedam Instead of declaring too many variables as in your source code, you can use an if-else construct inside the loop to complete the task.

Refer to the below code:

#include<bits/stdc++.h>
using namespace std;

int main(void) {
    int test;
    std :: cin >> test;
    while(test--) {
        unsigned int n, number_of_notes;
        std :: cin >> n;
        number_of_notes = 0;
        while(n) {
            if(n >= 100) {
                number_of_notes += n / 100;
                n %= 100;
            } else if(n >= 50) {
                number_of_notes += n / 50;
                n %= 50;
            } else if(n >= 10) {
                number_of_notes += n / 10;
                n %= 10;
            } else if(n >= 5) {
                number_of_notes += n / 5;
                n %= 5;
            } else if(n >= 2) {
                number_of_notes += n / 2;
                n %= 2;
            } else {
                number_of_notes += n;
                n = 0;
            }
        }
        std :: cout << number_of_notes << endl;
    }
    return 0;
}

You can refer to the solutions in other programming languages here: https://github.com/strikersps/Competitive-Programming/tree/master/Code-Chef/Smallest-Numbers-of-Notes