Answer to Question #273445 in C++ for Gillani

Question #273445

Faisal bank need a ATM machine. In this machine they need to add all possible currency divisions (1, 2, 5,


10, 20, 50, 100, 500, 1000, 5000). Write a C++ program in which, take required amount from user and find


the required currency division which will give to user in order to pay the required amount.


Example:


Sample input:


Enter required amount: 7895


Required currency division is:


5000: 1


1000: 2


500: 1


100: 3


50: 1


20: 2


10: 0


5: 1


2: 0


1: 0


Also make flowchart

1
Expert's answer
2021-12-01T06:40:45-0500
#include <iostream>
#include <iomanip>
using namespace std;




int main() {
    int Nom[10] = {1, 2, 5, 10, 20, 50, 100, 500, 1000, 5000};
    int Banknotes[10] = {0};
    int Amount;




    cout << "Enter Amount: ";
    cin >> Amount;
    if (Amount <= 0) {
        cout << "Invalid input" << endl;
        return 0;
    }




    int i = 9;
    while (Amount > 0) {
        if (Amount < Nom[i]) {
            i--;
            continue;
        }
        Amount -= Nom[i];
        Banknotes[i]++;
    }




    cout << endl;
    cout << "notes : number" << endl;
    for (i=9; i>=0; i--) {
        if (Banknotes[i] > 0) {
            cout << "   " << setw(2) << Nom[i] << " : " << Banknotes[i] << endl;
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

Johannes Haitembu
20.03.22, 17:54

Good site

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS