Build a function that does the following options and has a options menu displaye
ID: 3692349 • Letter: B
Question
Build a function that does the following options and has a options menu displayed as the following when run
lastly the resultant function must work (post a picture of it working in the cmd), the code has to be written in c and very simple in structure, the code has to contain #include and main(), and the code must be typed out.
Main menu: 1 Load item list 2 Save item list 3 Display items 4-Add item 5 Remove item 6 Search for item 7- Purchase item 8 -Exit Select an option: 3 Items available: Apple [121, Price: 0.50, 0ty: 10 Coconut [171, Price: 1.00, Oty: 5 Mango [15], Price: 0.75, Qty: 10 Pear [201, Price: .45, Qty: 10Explanation / Answer
#include <stdio.h>
#include <stdlib.h>
struct Items{
char Item_Name[20];
double price;
int quantity;
int itemcount;
}i1,*ptr;
void loadlist()
{
i1.Item_Name[20]="apple";
i1.price=0.5;
i1.quantity=10;
i1.itemcount++;
printf("----------loaded-------------");
}
void savelist()
{
ptr=&i1;
printf("---------saved----------------");
}
void display()
{ printf("----------Display----------- ");
printf("%s[%d], Price: %lf, Qty: %d ",i1.Item_Name,i1.itemcount,i1.price,i1.quantity);
}
void additem()
{
}
void removeitem()
{
}
void searchitem()
{
}
void purchaseitem()
{
}
int main()
{
int option;
char ch;
do{
printf("Main Menu 1 - load item list 2 - save item list 3 - display items4 - add item 5 - remove item 6 - search for item ");
printf("7 - purchase item 8 - exit Select an option : ");
scanf("%d",&option);
switch(option)
{
case 1: loadlist();break;
case 2: savelist();break;
case 3: display();break;
case 4: additem();break;
case 5: removeitem();break;
case 6: searchitem();break;
case 7: purchaseitem();break;
case 8: exit(0);
default : printf("choose correct option: ");
}
// printf("Again? [Y/N]: ");
// scanf("%c",&ch);
}while(option > 0 && option < 9 );
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.