WRITE A C LANGUAGE PROGRAM USING FUNCTION Program completion
WRITE A C LANGUAGE PROGRAM USING FUNCTION
Program completion
Your program is complete if your output matches the following output. bold numbers show the user’s input.
Start OUPUT
><
><
><
><
><
><
><
><
><
><
><
><
><
><
><
><
><
><
><
><
>Welcome to the Shop
>===================
>Please select from the following options:
>1) Display the inventory.
>2) Add to the inventory.
>3) Check price.
>4) Clear Screen.
>0) Exit.
>Select: 5
>Invalid input, try again: 2
>Please input a SKU number: 1234
>Quantity: 2
>Price: 45.63
>The item is successfully added to the inventory.
>Please select from the following options:
>1) Display the inventory.
>2) Add to the inventory.
>3) Check price.
>4) Clear Screen.
>0) Exit.
>Select: 2
>Please input a SKU number: 9010
>Quantity: 5
>Price: 23.50
>The item is successfully added to the inventory.
>Please select from the following options:
>1) Display the inventory.
>2) Add to the inventory.
>3) Check price.
>4) Clear Screen.
>0) Exit.
>Select: 2
>Please input a SKU number: 1234
>Quantity: 5
>The item exists in the repository, quantity is updated.
>Please select from the following options:
>1) Display the inventory.
>2) Add to the inventory.
>3) Check price.
>4) Clear Screen.
>0) Exit.
>Select: 1
><
><
>Inventory
>=========================================
>Sku Price Quantity
>1234 45.63 7
>9010 23.50 5
>=========================================
>Please select from the following options:
>1) Display the inventory.
>2) Add to the inventory.
>3) Check price.
>4) Clear Screen.
>0) Exit.
>Select: 0
>Goodbye!
><
Solution
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
struct inventory
{
int sku;
int quantity;
double price;
}st[100];
int main()
{
int ch;
int i=0;
printf(\"\ Welcome to the Shop\
==================
\ Please select from the following options:
\ 1) Display the inventory.
\ 2) Add to the inventory.
\ 3) Check price.
\ 4) Clear Screen.
\ 0) Exit.
\ Select: \");
scanf(\"%d\",&ch);
while(ch!=0)
{
switch(ch)
{
case 1:
printf(\"\ sku\\tprice\\tquantity\");
for(int j=0;j<=i;j++)
{
printf(\"\ %d\\t%lf\\t%d\",st[i].sku,st[i].price,st[i].quantity);
}
break;
case 2:
printf(\"\ enter sku :\");
int sku;
scanf(\"%d\",&sku);
int q;
printf(\"\ enter quantity :\");
scanf(\"%d\",&q);
double p;
printf(\"\ enter price :\");
scanf(\"%lf\",&p);
boolean flag=false;
int in;
in=++i;
for(int j=0;j<=i;j++)
{
if(st[j]==sku)
{
flag=true;
in=j;
break;
}
}
st[in].price=p;
st[in].quantity=q
st[in].sku=sku;
if(flag==true)
{
printf(\"\ item already exists ,quantityupdated\");
}
else
printf(\"\ item added\");
break;
case 3:
printf(\"\ enter sku :\");
int sku;
scanf(\"%d\",&sku);
boolean flag=false;
double p;
for(int j=0;j<=i;j++)
{
if(st[j].sku==sku)
{
flag=true;
p=st[j].price;
break;
}
}
if(flag==false)
printf(\"\ item not found\");
else
printf(\"\ price is%lf\",p);
break;
case 4:
clrscr();
break;
case 0:
printf(\"\ good bye\");
exit(0);
break;
default:
printf(\"\ invalid option,try again!\");
break;
}
printf(\"\ Welcome to the Shop\
==================
\ Please select from the following options:
\ 1) Display the inventory.
\ 2) Add to the inventory.
\ 3) Check price.
\ 4) Clear Screen.
\ 0) Exit.
\ Select: \");
scanf(\"%d\",&ch);
}
return 0;
}





