The change return program

21 Sep

Change Return Program – The user enters a cost and then the amount of money given. The program will figure out the change in Rs notes of 1000,500,100,50,10,1’s and paise.

#include<stdio.h>

void change(int,int,int,int,int,int,double);

int main()

{

      double amt,cash,bal;

      int th=0,fhd=0,hd=0,fifty=0,tens=0,ones=0;int notes,cnt=0,n1,i;

       printf(“enter the amount\n”);

       scanf(“%lf”,&amt);

       printf(“enter the cash recieved\n”);

       scanf(“%lf”,&cash);

      bal=cash-amt;

      printf(“change=%lf\n”,bal);

      notes=bal;

      bal=bal-notes;

     while(notes!=0)

     {

             n1=notes%10;

            if(cnt==0)

          {

                  i=0;

                  while(n1!=i)

                           i++;

                  ones=i;

        }

        elseif(cnt==1)

       {

              i=0;

              while(n1!=i)

              i++;

             if(i>=5 && i<=9)

            {

                  fifty++;

                  tens=i-5;

            }

           else

                tens=i;

         }

        elseif(cnt==2)

       {

            i=0;

            while(n1!=i)

                       i++;

           if(i>=5 && i<=9)

         {

                  fhd++;

              hd=i-5;

          }

        else

          hd=i;

        }

        elseif(cnt==3)

       {

            i=0;

             while(n1!=i)

                     i++;

             th=i;

        }

    notes=notes/10;

   cnt++;

 

  }

     change(th,fhd,hd,fifty,tens,ones,bal);

    return 0;

}

void change(int t,int fh,int hd,int fifty,int tens,int ones,doublep)

{

        if(t)

        printf(“1000 rs – %d\n”,t);if(fh)

        printf(“\t500 rs – %d\n”,fh);if(hd)

        printf(“\t100 rs – %d\n”,hd);if(fifty)

         printf(“\t50 rs – %d\n”,fifty);if(tens)

       printf(“\t10 rs – %d\n”,tens);if(ones)

        printf(“\t1 rupee – %d\n”,ones);if(p)

       printf(“\tpaise – %lf\n”,p);

}

Leave a comment