Write a C++ program to count the total number of notes in a given amount by using the switch statement.
Flowchart of the C++ program to count the total number of notes
C++ Source Code to count the total number of notes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | #include<iostream> using namespace std; int main() { int amount; int n1,n2,n5,n10,n20,n50,n100,n500; n1 = n2 = n5 = n10 = n20 = n50 = n100 = n500 =0; cout<<"Please Enter Your total Amount to find the notes : "; cin>>amount; switch(amount>=500) { case 1: n500 = amount/500; amount -= n500 * 500; break; } switch(amount >=100) { case 1: n100 = amount/100; amount -= n100 * 100; break; } switch(amount >=50) { case 1: n50 = amount/50; amount -= n50 * 50; } switch(amount >=20) { case 1: n20 = amount/20; amount -= n20 * 20; break; } switch(amount >=10) { case 1: n10 = amount/10; amount -= n10 * 10; break; } cout << "500 = " << n500 <<endl; cout << "100 = " << n100 <<endl; cout << "50 = " << n50 <<endl; cout << "20 = " << n20 <<endl; cout << "10 = " << n10 <<endl; } |
Output
Please Enter Your total Amount to find the notes :
120
500 = 0
100 = 1
50 = 0
20 = 1
10 = 0
SFT (Shamil’s Flow Table )
Are you interested to Read about SFT(Shamil’s Flow Table)?