Amount remaining after shopping (Id-3472)
Sherley goes for a shopping to a mall ‘M1’ . She uses credit card of bank ‘ABC’ for her purchases. Account details of each customer of ‘ABC’ contain Account holder name, Account number and Balance. Details of customers of mall ‘M1’ includes customer name and list of items purchased and cost of the items. Given the details of ‘n’ customers of bank ‘ABC’ and the purchase details of ‘m’ customers to mall ‘M1’, design an algorithm and write a C program to print the name of items purchased by Sherley and the balance amount in the account of Sherley in the bank ‘ABC’.
For example, if details (Name, Account number, Balance) of six customers of bank are given as follows:
Raju 12356 1000.00
Sam 12789 980.00
Ram 13457 975.50
Sherley 16789 1500.00
Sheela 17890 1345.50
Kamala 12378 2567.75
Details (Name, number of items purchased, item name1, cost1, item name2, cost2,...) of three customers of mall m1 are given as follows:
Ram 2 Bread 50.00 Jam 25.00
Sherley 3 Milk 20.00 Bread 50.00 Butter 31.50
Mukesh 4 Chocolate 15.00 Chips 12.50 Rice 29.00 Dall 31.25
Assume that the customer of mall has purchased only a maximum of ten items
Input Format
First line contains the number of customers of ABC bane, n
Next ‘n’ lines contain the details of customers of bank such as Account holder name, Account number and Balance in order and separated by space
Next line contains the number of customers to mall M1, m
Next ‘m’ lines contains the details of customers to mall such as name, number of items purchased ‘r’, 2*r detail such as item name and cost. Each detail is separated by a space
Output Format
Print name of the items purchased by Sherley, one item name in a line and balance amount in account of Sherley in the bank
solution:
c-code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct bank{
char name[50];
int accnumber;
float bal;
};
struct mall{
char name[50];
int items;
char iname[10][50];
float price[10];
};
void main(){
int n,m,i,j;
int x = -1;
int y = -1;
scanf("%d",&n);
struct bank c[n];
for(i=0; i<n; i++){
scanf("%s", c[i].name);
if(strcmp(c[i].name,"Sherley") == 0){
x= i;
}
scanf("%d", &c[i].accnumber);
scanf("%f", &c[i].bal);
}
scanf("%d",&m);
struct mall d[m];
for(i=0; i<m; i++){
scanf("%s", d[i].name);
if(strcmp(d[i].name,"Sherley") == 0){
y= i;
}
scanf("%d", &d[i].items);
for(j=0;j<d[i].items;j++){
scanf("%s",d[i].iname[j]);
scanf("%f", &d[i].price[j]);
if(i ==y){
printf("%s\n", d[i].iname[j]);
c[x].bal -= d[i].price[j];
}
}
}
printf("%.2f", c[x].bal);
}
0 Comments