Question: Hello ! I am just having trouble with the delete Auto function now. When I select 2 it just prints the List of Autos in

Hello !

I am just having trouble with the delete Auto function now. When I select 2 it just prints the "List of Autos in Inventory" and just immediately exits the program.

As always, all help is appreciated!

#include #include #define CLEAR system("cls") #define PAUSE system("pause") #define SIZE 100

typedef struct{ int year; char make[10]; char model[10]; char color[10]; char condition[10]; double price; }AUTO; int getChoice(); void addAuto(AUTO inventory[], int *esize); void deleteAuto(AUTO inventory[], int *esize); void displayInventory(AUTO inventory[], int esize);

int main(){ char choice; int esize = 0; AUTO inventory[SIZE]; do{ choice = getChoice(); switch(choice){ case 1: addAuto(inventory, &esize); break; case 2: deleteAuto(inventory, &esize); break; case 3: displayInventory(inventory, esize); break; case 4: printf("Exiting the program now, thank you for using my program. "); PAUSE; break; default: printf("Invalid selection, please select one of the options above. "); PAUSE; break; } } while (choice != 4); return 0; } int getChoice(){ int results; printf("Please make a selection: "); char menu[100]="1. Add a Auto 2. Delete Auto 3. Display Inventory 4. Exit "; printf("%s", menu); scanf("%i", &results); return results; } void addAuto(AUTO inventory[], int *esize){ if(*esize == SIZE){ printf("No additions allowed, inventory is full."); PAUSE; return; } printf(" Entering the data: "); printf(" Year: "); scanf("%d", &inventory[*esize].year); printf("Make: "); scanf("%s", inventory[*esize].make); printf("Model: "); scanf("%s", inventory[*esize].model); printf("Color: "); scanf("%s", inventory[*esize].color); printf("Condition: "); scanf("%s", inventory[*esize].condition); printf("Price: "); scanf("%lf", &inventory[*esize].price); *esize = *esize + 1; } void deleteAuto(AUTO inventory[], int *esize){ int index; int i, j; if(*esize == 0){ printf("No autos in inventory! "); return; }

printf("List of autos in inventory: "); for(i = 0; i < *esize; i++){ printf("%d. %s %s %s %s %f ", i+1, inventory[i].year, inventory[i].make, inventory[i].model, inventory[i].color, inventory[i].price); }

printf("Please enter the index of the auto you want to delete: "); scanf("%d", &index); index--;

for(j = index; j < *esize-1; j++){ inventory[j] = inventory[j+1]; }

*esize = *esize-1;

printf("Auto deleted successfully! "); } void displayInventory(AUTO inventory[], int esize){ int i; if(esize == 0){ printf("No autos in inventory! "); return; } printf("List of autos in inventory: "); for(i = 0; i < esize; i++){ printf("%d %d %s %s %s %s %.2f ", i+1, inventory[i].year, inventory[i].make, inventory[i].model, inventory[i].color, inventory[i].condition, inventory[i].price); } }

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!