Pages

Tuesday, October 26, 2010

Denomination of Money

PROBLEM:

The Philippine currency is one of the currencies in the world with many denominations:

1,000.00 –One thousand pesos
500.00       –Five hundred pesos
200.00   –Two hundred pesos
100.00    –One hundred pesos
50.00      –Fifty pesos
20.00     –Twenty pesos

10.00     –Ten pesos
5.00     –Five pesos
1.00    –One peso
0.25    –Twenty five centavo coin
0.10    –Ten centavo coin
0.05    –Five centavo coin and
0.01    –One centavo coin

Construct the flowchart and code the C program that reads in any amount in pesos and then display the different peso denomination that would equal to the amount entered.

#include<stdio.h>
#include<conio.h>

int main(void)
{
    float num;
    int cnt25,cnt10,cnt5,cnt1;
    int thou,fiveh,twoh,oneh,ffty,twnty,ten,p5,p1;
    float d1,d2,d3,d4,d5,d6,d7,d8,d9,d10,d11,d12;
    float athou,a500,a200,a100,a50,a20,a10,a5,a1;
    float a_25,a_10,a_5,a_1;

    clrscr();
    printf("\n\tEnter any amount in peso: ");
    scanf("%f",&num);

    thou =num/1000;
    athou =thou*1000;
    d1 =num-(athou);

    fiveh =d1/500;
    a500 =fiveh*500;
    d2 =num-(athou+a500);

    twoh =d2/200;
    a200 =twoh*200;
    d3 =num-(athou+a500+a200);

    oneh =d3/100;
    a100 =oneh*100;
    d4 =num-(athou+a500+a200+a100);

    ffty =d4/50;
    a50 =ffty*50;
    d5 =num-(athou+a500+a200+a100+a50);

    twnty =d5/20;
    a20 =twnty*20;
    d6 =num-(athou+a500+a200+a100+a50+a20);

    ten =d6/10;
    a10 =ten*10;
    d7 =num-(athou+a500+a200+a100+a50+a20+a10);

    p5 =d7/5;
    a5 =p5*5;
    d8 =num-(athou+a500+a200+a100+a50+a20+a10+a5);

    p1 =d8/1;
    a1 =p1*1;
    d9 =num-(athou+a500+a200+a100+a50+a20+a10+a5+a1);

    cnt25 =d9/0.25;
    a_25 =cnt25*0.25;
    d10 =num-(athou+a500+a200+a100+a50+a20+a10+a5+a1+a_25);

    cnt10 =d10/0.10;
    a_10 =cnt10*.10;
    d11 =num-(athou+a500+a200+a100+a50+a20+a10+a5+a1+a_10+a_25);

    cnt5 =d11/0.05;
    a_5 =cnt5*0.05;
    d12 =num-(athou+a500+a200+a100+a50+a20+a10+a5+a1+a_10+a_5+a_25);

    cnt1 =d12/0.01;
    a_1 =cnt1*0.01;

    printf("\n\t%.2f in different peso denominations:",num);
    printf("\n\n\tPeso Denomination       Pcs       Amount");
    printf("\n\t----------------------------------     ----------    ---------------");
    printf("\n\t 1,000.00        %d         %.2f",thou,athou);
    printf("\n\t    500.00        %d         %.2f",fiveh,a500);
    printf("\n\t    200.00                  %d         %.2f",twoh,a200);
    printf("\n\t    100.00                    %d         %.2f",oneh,a100);
    printf("\n\t      50.00                  %d         %.2f",ffty,a50);
    printf("\n\t      20.00                   %d         %.2f",twnty,a20);
    printf("\n\t      10.00                  %d         %.2f",ten,a10);
    printf("\n\t        5.00                 %d         %.2f",p5,a5);
    printf("\n\t        1.00                   %d         %.2f",p1,a1);
    printf("\n\t        0.25                   %d         %.2f",cnt25,a_25);
    printf("\n\t        0.10                   %d         %.2f",cnt10,a_10);
    printf("\n\t        0.05                   %d         %.2f",cnt5,a_5);
    printf("\n\t        0.01                  %d         %.2f ",cnt1,a_1);
    printf("\n\t                                            -----------------");
    printf("\n\t                           TOTAL:           %.2f",num);

    getch();
}

3 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. sir/ma'am what if like this
    enter amount:165
    denomination:
    One Hundred: 1
    Fifty Pesos:1
    Ten Pesos:1
    Five Pesos:1
    -thanks

    ReplyDelete
  3. Thanks for your insight for your fantastic posting. I’m glad I have taken the time to see this. convert money online

    ReplyDelete