Must be done in C
This C Program performs ATM transaction. The type of ATM transaction is:
Cash withdrawal
Cash available to withdraw $2540
$2540 will be withdrawn.
Will be withdrawn in bills of:
$1000 (Two $1000 bills)
$500 (One $500 bill)
$20 (One $20 bill)
$10 (One $10 bill)
$5 (One $5 bill)
$2 (Two $2 bill)
$1 (One $1 bill)
Show steps with comments. Make it simple and nothing complicated please.
Please find below code and don't forget to give a Like.
#include <stdio.h>
int main()
{
int totalcash=2540,temp; /* created a integer total cash for 2540
*/
/* Since we need change so we created change of size 7 which is
array */
int cashchange[7]={1000,500,20,10,5,2,1};
/* we need to show the count of cash that is required */
int count[7]={0,0,0,0,0,0,0};
int i=0;
temp=totalcash;
/* this should check all the coins so while loop*/
while(i<=6){
/* checking whether every change is lessthan or equal to total cash
if so we reduce that change from total */
if(cashchange[i]<=totalcash){
totalcash=totalcash-cashchange[i];
/* making count of that particular coin */
count[i]=count[i]+1;
}
/* since repetition of that coin is allowed so we take increment(to
go to next coin) in else loop */
else{
i++;
}
}
printf("Cash withdrawal\n");
printf("Cash availble to withdrawn $%d",temp);
printf("\n$%d will be withdrawn\n",temp);
printf("Will be withdrawn in the bills of:\n");
/* to print all the coins we use for loop which rotates all the
elements */
for(int j=0;j<=6;j++){
if(count[i]!=0){
printf("$%d(%d $%d
bills)",cashchange[j],count[j],cashchange[j]);
printf("\n");
}
}
return 0;
}
Output will be:
Cash withdrawal
Cash availble to withdrawn $2540
$2540 will be withdrawn
Will be withdrawn in the bills of:
$1000(2 $1000 bills)
$500(1 $500 bills)
$20(2 $20 bills)
$10(0 $10 bills)
$5(0 $5 bills)
$2(0 $2 bills)
$1(0 $1 bills)
Since 40 totalcash is available so it will take 2 20s to complete the task instead of 1.
$2 (Two $2 bill) - here you mentioned two $2... If there is 40 cash then system will prefer two $20s than going to $10 when we compare with your example then code should work perfectly.
Get Answers For Free
Most questions answered within 1 hours.