I have a program where the user is prompted to either list inventory, search inv
ID: 3641061 • Letter: I
Question
I have a program where the user is prompted to either list inventory, search inventory, or enter inventory. In the main program parts is declared as: inventory parts[num], where num is defined as 5.
The getInventory() function works fine. However i cannot get the displayInventory function to work when passing "parts". The function HAS to be passed (inventory parts, int num).
I also need a function to search inventory, also passing (inventory parts, int num)
#ifndef _INVENTORY
#define _INVENTOR
#include <stdio.h>
typedef struct INVEN
{
char PN [7];
char DES[165];
char MAN [4];
double cost;
double price;
int qty;
int reo;} inventory;
//prototypes
void getInventory(inventory *, int);
void displayInventory(inventory, int);
void ignor_to_nl(void);
#endif
void getInventory (inventory *parts, int num)
{
inventory *part;
part=parts;
printf("Enter the part number (up to 6 characters): ");
scanf(" %6[^ ]", part->PN);
ignor_to_nl();
printf("Enter the description (up to 15 characters): ");
scanf(" %15[^ ]", part->DES);
ignor_to_nl();
printf("Enter the manufacturer code (up to 3 characters): ");
scanf(" %3[^ ]", part->MAN);
ignor_to_nl();
printf("Enter the cost: ");
scanf("%lg", &(part->cost));
ignor_to_nl();
printf("Enter the price: ");
scanf("%lg", &(part->price));
ignor_to_nl();
printf("Enter the qty on hand: ");
scanf("%i", &(part->qty));
ignor_to_nl();
printf("Enter the reorder level: ");
scanf("%i", &(part->reo));
ignor_to_nl();
puts("");
return;
}
//function to display inventory
//parameters must be (inventory parts, int num)
void displayInventory(inventory part, int num)
{
printf("Part number: %s ", part.PN);
printf("Part description: %s ", part.DES);
printf("Part manufacturer: %s ", part.MAN);
printf("Cost $%6.2f selling price: $%6.2f "
" ", part.cost, part.price);
printf("Quantity %i reorder level %i ", part.qty, part.reo);
return;
}
//function to search inventory
//parameters must be (inventory parts, int num)
void searchInventory (inventory parts, int num)
{
}
void ignor_to_nl(void)
{
while(getchar()!=' ');
return;
}
Explanation / Answer
Please rate...
#ifndef _INVENTORY
#define _INVENTOR
#include <stdio.h>
#define NUM 5
#include<ctype.h>
typedef struct INVEN
{
char PN [7];
char DES[165];
char MAN [4];
double cost;
double price;
int qty;
int reo;} inventory;
//prototypes
void getInventory(inventory *, int);
void displayInventory(inventory *, int);
void searchInventory(inventory [],int);
void ignor_to_nl(void);
#endif
void getInventory (inventory *parts, int num)
{
inventory *part;
part=parts;
printf("Enter the part number (up to 6 characters): ");
scanf(" %6[^ ]", part->PN);
ignor_to_nl();
printf("Enter the description (up to 15 characters): ");
scanf(" %15[^ ]", part->DES);
ignor_to_nl();
printf("Enter the manufacturer code (up to 3 characters): ");
scanf(" %3[^ ]", part->MAN);
ignor_to_nl();
printf("Enter the cost: ");
scanf("%lg", &(part->cost));
ignor_to_nl();
printf("Enter the price: ");
scanf("%lg", &(part->price));
ignor_to_nl();
printf("Enter the qty on hand: ");
scanf("%i", &(part->qty));
ignor_to_nl();
printf("Enter the reorder level: ");
scanf("%i", &(part->reo));
ignor_to_nl();
puts("");
return;
}
//function to display inventory
//parameters must be (inventory parts, int num)
void displayInventory(inventory *part, int num)
{
printf("Part number: %s ", part->PN);
printf("Part description: %s ", part->DES);
printf("Part manufacturer: %s ", part->MAN);
printf("Cost $%6.2f selling price: $%6.2f "
" ", part->cost, part->price);
printf("Quantity %i reorder level %i ", part->qty, part->reo);
return;
}
//function to search inventory
//parameters must be (inventory parts, int num)
void searchInventory (inventory parts[], int num)
{
int i;
char a[7];
printf(" Enter the part number of product to be searched: ");
scanf(" %6[^ ]",a);
ignor_to_nl();
for(i=0;i<num;i++)
{
if(strcmp(parts[i].PN,a)==0){
printf(" Inventory found, DETAILS: ");
displayInventory(&parts[i],num);
}
else printf(" Item not on the inventory list");
}
}
void ignor_to_nl(void)
{
while(getchar()!=' ');
return;
}
void main()
{
int i;
inventory parts[NUM];
for(i=0;i<NUM;i++)
{
getInventory(&parts[i], NUM);
}
for(i=0;i<NUM;i++)
{
displayInventory(&parts[i] , NUM);
}
searchInventory(parts,NUM);
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.