Answer to Question #273232 in C++ for Gillani

Question #273232

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.

1
Expert's answer
2021-11-29T10:31:19-0500
#include <iostream>
#include <iomanip>
using namespace std;

int main() {
    int nominals[10] = {1, 2, 5, 10, 20, 50, 100, 500, 1000, 5000};
    int banknotes[10] = {0};
    int amount;

    cout << "Enter an amout to be payed: ";
    cin >> amount;
    if (amount <= 0) {
        cout << "Incorrect input" << endl;
        return 0;
    }

    int i = 9;
    while (amount > 0) {
        if (amount < nominals[i]) {
            i--;
            continue;
        }
        amount -= nominals[i];
        banknotes[i]++;
    }

    cout << endl;
    cout << "nominal | number" << endl;
    for (i=9; i>=0; i--) {
        if (banknotes[i] > 0) {
            cout << "   " << setw(4) << nominals[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

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS