Question: Hi can someone fix my code, This is the criteria I need to meet (I don't know how to code find can someone help me

Hi can someone fix my code,

This is the criteria I need to meet (I don't know how to code find can someone help me with that)

  • add: Add a new record in the database
  • printall: Print all records in the database
  • find: Find record(s) with a specified account #
  • delete: Delete existing record(s) from the database using the account # as a key
  • quit: Quit the program

Here is my code:

#include #include typedef struct node { int accountno; float balance; struct node *next; } *head;

void menu() {

printf("Greetings, what do you want to do with the database? "); printf("------------------------------------------------------------------------ ");

printf(" 1. add "); printf("2. delete "); printf("3. print all "); printf("4. quit "); }

struct node* add_customer(struct node *head ,int accNo , float balance) { struct node *temp = (struct node*)malloc(sizeof(struct node)); temp->accountno = accNo; temp->balance=balance; temp->next=NULL; head->next=temp; return head; } void print(struct node *head) { struct node *temp = (struct node*)malloc(sizeof(struct node)); temp=head; printf("Details : "); while(temp!=NULL) { printf("%d ",temp->accountno); printf("%f ",temp->balance); printf(" "); temp=temp->next; }

} struct node* deleteCustomer(struct node *head, int key) { // Store head node struct node *temp = (struct node*)malloc(sizeof(struct node)); temp=head; struct node *prev = (struct node*)malloc(sizeof(struct node)); prev=NULL; // If head node itself holds // the key to be deleted if (temp != NULL && temp->accountno == key) { head = temp->next; // Changed head // free old head return head; } // Else Search for the key to be deleted, // keep track of the previous node as we // need to change 'prev->next' */ else { while (temp != NULL && temp->accountno != key) { prev = temp; temp = temp->next; } // If key was not present in linked list if (temp == NULL) return head; // Unlink the node from linked list prev->next = temp->next; return head; } }

// main method int main(int argc, char *argv[]) { struct node *head = (struct node*)malloc(sizeof(struct node)); //setting fist customer to NULL head->accountno=0; head->balance=0.0; head->next=NULL;

int flag = 1; while(flag){ menu(); printf("Enter your choice: "); //reading choice int ch ; scanf("%d", &ch); printf(" "); // use switch instead if-else if, // using switch case for menu is better. I tried using switch upon seeing Lenora's code during the meeting. switch (ch) { case 1: //reading details for bank customer printf("Enter account number: "); int accNum = 0; scanf("%d", &accNum); printf("Enter balance: "); float curbalance; scanf("%f", &curbalance); head=add_customer(head,accNum,curbalance); break; case 2: //fetching an account number, removing customer printf("Enter account number: "); int tempaccNum = 0; scanf("%d",&tempaccNum); head = deleteCustomer(head,tempaccNum); break; case 3: //printing customers print(head); break; case 4: flag=0; break; } } }

Here is the database that must be pass to my code:

int addRecord (struct record **, int, char [ ],char [ ]); void printAllRecords(struct record *); int findRecord (struct record *, int); int deleteRecord(struct record **, int);

Please help me fix my code thanks.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!