Tuesday, 27 January 2015

Bank note

#include<conio.h>
#include<stdio.h>
int totalThousand=1000;
int totalFiveHundred=1000;
int totalOneHundred=1000;
int main()
{
clrscr();
unsigned long withdrawAmount;
unsigned long totalMoney;
int thousand=0,fiveHundred=0,oneHundred=0;
printf("enter the amount in multiple of 100: ");
scanf("%lu",&withdrawAmount);
if(withdrawAmount%100!=0)
{
printf("invalid amount");
return 0;
}
totalMoney=totalThousand*1000+totalFiveHundred*500+totalOneHundred*100;
if(withdrawAmount>totalMoney)
{
printf("sorry, insufficient money");
return 0;
}
thousand=withdrawAmount/1000;
if(thousand>totalThousand)
thousand=totalThousand;
withdrawAmount=withdrawAmount-thousand*1000;
if(withdrawAmount>0)
{
fiveHundred=withdrawAmount/500;
if(fiveHundred>totalFiveHundred)
fiveHundred=totalFiveHundred;
withdrawAmount=withdrawAmount-fiveHundred*500;
}
if(withdrawAmount>0)
oneHundred=withdrawAmount/100;
printf("total 1000 notes: %d \n",thousand);
printf("total 500 notes: %d \n",fiveHundred);
printf("total 100 notes: %d",oneHundred);
getch();
return 0;
}

No comments:

Post a Comment