
I'm trying to delete a node after inputting data for 2-3 checks but the node I try to delete remains in the list. How do I fix my deleteCheck() function to run correctly with the rest of my code? Thank you.
#include <stdio.h>
#include <stdlib.h>
// Austin Chong
// The core concept of this assignment is to use a linked list in a C program.
// 07 March 2020
struct checkNode
{
int checkNumber;
char date[8];
char paidTo[100];
char description[100];
double amount;
struct checkNode *head;
struct checkNode *next;
};
struct checkNode *checkBook = NULL;
/* Functions */
void addCheck()
{
int checkNumber;
double amount;
char temp;
struct checkNode *newCheck = (struct checkNode*) malloc(sizeof(struct checkNode));
printf("Please enter the check number: ");
scanf("%d", &checkNumber);
newCheck -> checkNumber = checkNumber;
printf("Please enter the amount: ");
scanf("%lf", &amount);
newCheck -> amount = amount;
printf("Please enter the date: ");
scanf("%c", &temp);
scanf("%[^\n]", newCheck -> date);
printf("Please enter the person receiving the check: ");
scanf("%c", &temp);
scanf("%[^\n]", newCheck -> paidTo);
printf("Enter a description for the check: ");
scanf("%c", &temp);
scanf("%[^\n]", newCheck -> description);
if(checkBook == NULL)
{
checkBook = newCheck;
checkBook -> head = newCheck;
newCheck -> next = NULL;
} else {
struct checkNode *tNode;
tNode = checkBook -> head;
while(tNode -> next != NULL)
{
tNode = tNode -> next;
}
tNode -> next = newCheck;
}
printf("\nNew check added successfully!\n");
}
void deleteCheck()
{
int deletedCheck;
if(checkBook == NULL)
{
printf("\nThe checkbook is currently empty.\n");
return;
}
struct checkNode *temp;
temp = checkBook -> head;
if(checkBook != NULL)
{
printf("Please enter which check number you would like to delete: ");
scanf("%d", &deletedCheck);
if(temp -> checkNumber == deletedCheck) {
checkBook -> head = temp -> next;
free(temp);
}
}
}
void displayCheck()
{
int count = 0;
if(checkBook == NULL)
{
printf("There are no checks to display.\n");
return;
}
printf("Please enter the check number: ");
scanf("%d", &count);
struct checkNode *temp;
temp = checkBook -> head;
while(temp != NULL)
{
if(temp -> checkNumber == count)
{
printf("The amount listed on the check is: %lf\n", temp -> amount);
printf("The date on this check is: %s\n", temp -> date);
printf("The person that received this check is: %s\n", temp -> paidTo);
printf("The description listed for this check is: %s\n", temp -> description);
return;
} else {
temp = temp -> next;
}
}
}
void displayAll()
{
struct checkNode *temp;
temp = checkBook -> head;
if(temp == NULL)
{
printf("There are no checks to display.\n");
return;
} else {
while(temp != NULL)
{
printf("The information of check #%d is:\n", temp -> checkNumber);
printf("Amount: %lf\n", temp -> amount);
printf("Date: %s\n", temp -> date);
printf("Person Received: %s\n", temp -> paidTo);
printf("Description: %s\n\n", temp -> description);
temp = temp -> next;
}
}
}
int main()
{
int option;
while(1)
{
printf("\n1. Add a check.\n");
printf("2. Display single check.\n");
printf("3. Display all checks.\n");
printf("4. Delete a check.\n");
printf("5. Quit.\n");
scanf("%d", &option);
switch(option)
{
case 1:
addCheck();
break;
case 2:
displayCheck();
break;
case 3:
displayAll();
break;
case 4:
deleteCheck();
break;
case 5:
printf("Good bye!\n");
exit(0);
default:
printf("Choose a different option.\n");
}
}
}

Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 2 images

- Please do it on c++ don't use stl function must read the instructionarrow_forwardWrite a function with the signature below that returns the sum of the last k elements of a singly linked list that contains integers. int returnSumOfLastKNodes(Node* head, int k) Example: 10 -> 5->8->15->11->9->23 10 represents the head node, returnSumOfLastKNodes(Node* head, 4) will return 58.arrow_forwardPlease help with C++ question in image. Thank you!arrow_forward
- Code in Python:arrow_forwardNo explicit loops must be used. In C# Suppose variable nums contains a list of integers.List«Integer> nums = Arrays.asList(1, 1, 2, 3, 4, 1, 3, 2, 4, 3, 3, 1);var nums = new List<int> { 1, 1, 2, 3, 4, 1, 3, 2, 4, 3, 3, 1 }; // C#Using Java Stream API *or* LINQ, write a short code that prints the following.For each section indicate the platform (whether the solution is given in Java orC# ILINQ).A) Print all numbers.B) Print the sum() of the numbers.C) count how many times number '1' appears in the list.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





