Untitled

mail@pastecode.io avatar
unknown
c_cpp
2 years ago
2.5 kB
2
Indexable
Never
#include <iostream>
using namespace std;

int main() {
    
    int total_balance, withdraw_amount;
    
    // Constant values (Can be changed to be inputted by user)
    const int lowest_withdrawable = 500;
    const int withdraw_limit = 50000;
    // Only multiples of lowest_withdrawable can be withdrawn
    
    // Prefix of currency
    char* currency_prefix = "Rs. ";
    
    // Taking input
    cout << "Total bank balance: ";
    cin >> total_balance;
    
    cout << "Amount to withdraw: ";
    cin >> withdraw_amount;

    
    // Error handling
    bool error = false;
    if (withdraw_amount % lowest_withdrawable != 0)
    {
        cout << "Error: You can only withdraw multiples of " << lowest_withdrawable << endl;
        error = true;
    }
    else if (withdraw_amount < lowest_withdrawable)
    {
        cout << "Error: You can only withdraw an amount greater than " << lowest_withdrawable << endl;
        error = true;
    }
    else if (withdraw_amount > total_balance)
    {
        cout << "Error: Insufficient balance" << endl;
        error = true;
    }
    if (error)
    {
        return 0;
    }
    
    int remaining_balance = total_balance - withdraw_amount;
    
    int lowest_note_number = 0; // Number of lowest value notes
    int double_note_number = 0; // Number of the second lowest value note. Its value is double that of the lowest value note
    int ten_note_number = 0; // Number of highest value note (in this case). Its value is ten times that of the lowest value note
    
    // At least one lowest value note will be withdrawn
    // Logic for distributing amount in notes
    while (withdraw_amount >= lowest_withdrawable)
    {
        withdraw_amount -= lowest_withdrawable;
        lowest_note_number++;
        if (lowest_note_number > 2)
        {
            double_note_number++;
            lowest_note_number = 1;
        }
        if (double_note_number >= 5)
        {
            ten_note_number++;
            double_note_number = 0;
        }
    }
    
    cout << "\nWithdrawal Complete!\n";
    cout << "Remaining balance: " << remaining_balance << endl;
    cout << "Number of " << currency_prefix << (lowest_withdrawable) << " notes: " << lowest_note_number << endl;
    cout << "Number of " << currency_prefix << (lowest_withdrawable * 2) << " notes: " << double_note_number << endl;
    cout << "Number of " << currency_prefix << (lowest_withdrawable * 10) << " notes: " << ten_note_number << endl;
    
    return 0;
}