Can you solve this question with explanation You are suppose
Solution
#include<stdio.h>
void takeCustomerDetails();
int askTransactionType();
int customerExists(int customerId);
void printRecipt(int customerIndex);
struct customer
{
char name[100];
char surName[100];
int id;
int transaction_type[100];
double transaction_amount[100];
int lastTransaction;
};
int current_index = 0,customer_index=0;
struct customer customers[100];
main()
{
int type;
float money;
int lastTransaction;
while(true)
{
takeCustomerDetails();
type = askTransactionType();
if(type == 4)
{
break;
}
printf(\"Enter amount : \");
scanf(\"%f\",&money);
lastTransaction = customers[customer_index].lastTransaction;
customers[customer_index].transaction_type[lastTransaction] = type;
customers[customer_index].transaction_amount[lastTransaction] = money;
customers[customer_index].lastTransaction++;
printf(\"--------------------------------------------------\ \");
printRecipt(customer_index);
printf(\"--------------------------------------------------\ \");
}
}
void printRecipt(int customerIndex){
customer currentCustomer = customers[customerIndex];
for(int count=currentCustomer.lastTransaction-1;count>=0;count--)
{
if(currentCustomer.transaction_type[count] == 1)
{
printf(\"the customer withdraws %f dollars from account\ \",currentCustomer.transaction_amount[count]);
}
else if(currentCustomer.transaction_type[count] == 2)
{
printf(\"the customer deposits %f dollars from account\ \",currentCustomer.transaction_amount[count]);
}
else if(currentCustomer.transaction_type[count] == 3)
{
printf(\"the customer lends %f dollars from account\ \",currentCustomer.transaction_amount[count]);
}
}
}
void takeCustomerDetails()
{
printf(\"Enter customer id : \");
int custId;
scanf(\"%d\",&custId);
customer_index = customerExists(custId);
if(customer_index == -1)
{
customers[current_index].id = custId;
printf(\"Enter customer name : \");
scanf(\"%s\",customers[current_index].name);
printf(\"Enter surname: \");
scanf(\"%s\",customers[current_index].surName);
customer_index = current_index++;
}
}
int customerExists(int customerId)
{
int i,size=sizeof(customers)/sizeof(customers[0]);
for(i=0;i<sizeof(customers)/sizeof(customers[0]);i++)
{
if(customers[i].id == customerId)
{
return i;
}
}
return -1;
}
int askTransactionType(){
printf(\"1. Withdraw money\ \");
printf(\"2. Deposit money\ \");
printf(\"3. Lend money at interest\ \");
printf(\"4. Exit\ \");
int option;
scanf(\"%d\",&option);
return option;
}

