Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Prodentim Probiotics Specially Designed For The Health Of Your Teeth And Gums

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Teach Your Child To Read

Powerful WordPress hosting for WordPress professionals

Disclosure: My content contains affiliate links.

31,104 questions

40,777 answers

573 users

How to divide a given amount into different bills (banknote) and coins in C++

1 Answer

0 votes
#include <iostream>

int main() {
    int bills_coins[9] = {1000, 500, 100, 50, 20, 10, 5, 2, 1};
    int amount = 9725;
    
    int tmp = amount;
    for (int i = 0; i < 9; i++) {
 	    std::cout << bills_coins[i] << " = " << tmp / bills_coins[i] << "\n";
 	    tmp = tmp % bills_coins[i];
    }

    return 0;
}


 
 
 
/*
run:
 
1000 = 9
500 = 1
100 = 2
50 = 0
20 = 1
10 = 0
5 = 1
2 = 0
1 = 0

*/

 





answered Jan 8, 2022 by avibootz
...