this is what i have now and i am missing a few parts #include<stdio.h> void addT
ID: 3657202 • Letter: T
Question
this is what i have now and i am missing a few parts
#include<stdio.h>
void addToInventory();
void displayInventory();
int main (void)
{
int choice;
int quantity[100];
int total=0;
char name[100][20];
float price[100];
FILE *inputfile;
inputfile=fopen("inventory.dat","w");
do {printf("Please select a choice ");
printf("1.Add to the Inventory ");
printf("2.Adjust Quantity of an Item ");
printf("3.Print Inventory ");
printf("4.Remove an Item from Inventory ");
printf("5.Quit ");
scanf("%d",&choice);
switch(choice) {
case 1:
printf("*****User choose to Add to the Inventory***** ");
addToInventory(name,price,quantity,&total);
break;
case 2:
printf("*****User choose to Adjust Qantity of an item***** ");
break;
case 3:
printf("*****User choose to Print Inventory***** ");
displayInventory(name,price,quantity,total);
break;
case 4:
printf("*****User choose to Remove an item from Inventory***** ");
break;
default:
printf("User chose to quit ");
break;
}
}
while(choice!=5);
return 0;
}
void addToInventory(char name[100][20],float price[100],int quantity[100],int *total)
{
printf("What is the the name of the first item? ");
scanf("%s", name[*total]);
printf("What is the quantity that is in stock? ");
scanf("%d", &quantity[*total]);
printf("What is the price of the item? ");
scanf("%f", &price[*total]);
(*total)++;
}
void displayInventory(char name[100][20],float price[100],int quantity[100],int total)
{
int counter;
for(counter=0;counter<total;counter++){
printf("%s %4.2f%d ",name[counter],price[counter],quantity[counter]);
}
}
Explanation / Answer
/* you may also download the code from......http://www.2shared.com/file/s0yR7pt-/INVENTORY.html*/ #include void addToInventory(); void displayInventory(); int main (void) { int choice; int quantity[100]; int total=0; int counter; char name[100][20]; float price[100]; FILE *inputfile; inputfile=fopen("inventory.txt","w"); do { printf("Please select a choice "); printf("1.Add to the Inventory "); printf("2.Adjust Quantity of an Item "); printf("3.Print Inventory "); printf("4.Remove an Item from Inventory "); printf("5.Quit "); scanf("%d",&choice); switch(choice) { case 1:printf("*****User choose to Add to the Inventory***** "); addToInventory(name,price,quantity,&total); break; case 2:printf("*****User choose to Adjust Qantity of an item***** "); break; case 3:printf("*****User choose to Print Inventory***** "); displayInventory(name,price,quantity,total); break; case 4:printf("*****User choose to Remove an item from Inventory***** "); break; default:printf("User chose to quit "); break; } } while(choice!=5); for(counter=0;counter
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.