Computer Science, asked by adityanirgude22, 9 days ago

A store has different categories of products in stock as shown below. Item Number=[101, 102, 103, 1047 57 Item Name= [Milk, Cheese, Price= [42, 50, 500, 40] Stock=[10, 20, 15, 16] ,ghee Bread] When user give input with 2 values as - 1. Item number for item which user wish to buy. 2. Quantity for the item entered above. When user enters above input, the 16 de should check the Stock user Calculate. 1. If quantity is less than stock and item is available display a notification message showing Output Line1- INR price in float with precision1 Output Line2- LEFT i/updated stock for Item after purchase 2. If the quantity in stock is less than quantity entered by user while placing order, then display message: Output Line1- NO STOCK Output Line2- LEFT 3. If user enter character as input for item number and quantity or enter item number which is not available then display following message and stop, . Output Line 1- INVALID INPUT

Answers

Answered by jayashrinirgude8140
36

C

#include<stdio.h>

void main()

{

int m=10,c=20,g=15,b=16; //stock

float p_m=42,p_c=50,p_g=500,p_b=40; //price

int choice,q; //quatity

scanf("%d",&choice);

scanf("%d",&q);

switch(choice)

{

case 101:

if(q<=m)

{

printf("%f\n",q*p_m); // price of total

printf("%dLEFT\n",m-q); // updated stock

}

else

{

printf("No Stock\n");

printf("%d\n",m);

}

break;

case 102:

if(q<=c)

{

printf("%f\n",q*p_c);

printf("%d\n",c-q);

}

else

{

printf("No Stock\n");

printf("%d\n",c);

}

break;

case 103:

if(q<=g)

{

printf("%f\n",q*p_g);

printf("%d\n",g-q);

}

else

{

printf("No Stock\n");

printf("%d\n",g);

}

break;

case 104:

if(q<=b)

{

printf("%f\n",q*p_b);

printf("%d\n",b-q);

}

else

{

printf("No Stock\n");

printf("%d\n",b);

}

break;

}

}

Answered by pruthaasl
0

Answer:

#include <iostream>

#include <iomanip>

using namespace std;

int main() {

   int i_num[4]={101,102,103,104};

   string i_name[4]={"Milk", "Cheese", "Ghee", "Bread"};

   float price[4]= {42.0,50.0,500.0,40.0};

   int stock[4]={10,20,15,16};

   int n, q,i;

   cout<<"Milk:101, Cheese:102, Ghee:103, Bread:104";

   cout<<"\nEnter item number and quantity: ";

   cin>>n>>q;

   for(i=0;i<4;i++)

   {

       if(i_num[i]==n)

       {

           if(stock[i]>=q)

           {

           cout<<"\nINR "<<price[i];

           stock[i]-=q;

           }

           else

           {

           cout<<"\nNo stock.";

           }

           cout<<"\nStock left: "<<stock[i];

           break;

       }

       cout<<"INVALID INPUT.";

   }

   return 0;

}

Explanation:

  • Declare and initialize four different arrays to store item number, item name, price, and stock availability and variables to store the inputs.
  • Take input as item number and quantity from the user and store them in the respective variables declared.
  • Check whether the entered item number is present in the array of the item number.
  • If is it present, check whether the stock available is greater than the quantity.
  • If the stock is greater than the required quantity, the price of the item is printed and the stock left after the purchase is displayed.
  • If the stock is less than the entered quantity, a message is displayed and the stock available is displayed.
  • If the entered item number is not present in the array, a message saying invalid input is displayed.

#SPJ3

Similar questions