C++ Program to Read an Amount and Find Number of Notes

C++ program to count all notes in a certain quantity – In this unique essay, we’ll go over the many C++programming techniques for counting all the notes in a certain quantity.

The following are the methods used in C++ programming to determine how many notes overall there are in a given quantity:

  • Using the Standard Procedure
  • Making Use of User-Defined Function
  • Employing Pointers

As we all know, with cash bundles, a number of notes combine to equal the exact quantity of money that the person in question needs.

Similar to that, this blog discusses the various methods for counting the number of notes in a certain amount. In a bundle, a single note’s multiples are multiplied.

The total number of notes in a particular quantity can be counted using a C++ program. Check out the whole code with example programs and sample outputs here. You can check out more introductory C++ programs here.

Thus, there are a number of ways to calculate notes in a given quantity in C++ programming, as follows:

C++ Program to Read an Amount and Find Number of Notes

Logic to count minimum number of denomination for given amount

There are numerous efficient algorithms available to address the given issue. To simplify things for this experiment, I utilized the greedy method.

Using descriptive logic, determine the least amount of denominations.

Amount entered by the user. Put it in a variable, like amt.
If the amount is higher than 500, divide it by 500 to get the maximum number of notes needed, which is 500. Put the result of the division in a variable, such as note500 = amt / 500;.
Divide the original sum by 500 notes, and then deduct the result. Execute note500 * 500 – amt.

For each note, repeat the previous step 200, 100, 50, 20, 10, 5, 2, and 1.

#include<iostream>

using namespace std;

class money{

public:

    int note_size[9]={1000,500,200,100,50,20,10,5,2};

    int note_count[9]={0};

     money(int amount){

        for (int i=0;i<9;i++){

            if(amount>=note_size[i]){

                note_count[i]=amount/note_size[i];

                amount=amount%note_size[i];

            }

        }

        cout<<"counted notes >>"<<endl;

        for (int i=0;i<9;i++){

            if(note_count[i]!=0){ cout<<note_size[i]<<" taka x"<<note_count[i]<<endl;

            }   }                 }  };

int main(){   int amount;

cout<<"enter total amount : "; //C++ Program to Read an Amount and Find Number of Notes

cin >>amount;

money ob(amount);

return 0;}

Output:

C++ Program to Read an Amount and Find Number of Notes

Understanding Conditional Statements in C Programming, If Else in C

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top
NEW TOXIC ROCKET CYCLE DECK in Clash Royale 2023 Best Deck in Clash Royale Best Deck for Arena 8 in Clash Royale Best Hog deck for Pro players Best Clash Royale Deck