THIS QUESTION IS FROM CHAPTER ARRAY AND LOOPS USE C LNAGUAGE

THIS QUESTION IS FROM CHAPTER ARRAY AND LOOPS ***USE C LNAGUAGE ***i want to run this on matrix

Design and code a program that lists the packaged goods in a grocery store and calculates their total value. Your program prompts the user for and accepts each item\'s

barcode

price

quantity in stock

Your program stops accepting data when the user enters 0 for the barcode.

Your program uses arrays, includes functions to validate the input and calculates the total value of the inventory. You may assume that there are no more than 100 items to process, but write your code so that you can change this limit by editing a single statement.

Preface each function header with a comprehensive description of the function\'s purpose, the function\'s parameters and the function\'s return value.

The output from your program looks like:

Solution

#include <stdio.h>
int main()
{
   float total_inventory_value=0;
   int arr1[100];
   int arr2[100];
   int arr3[100];
   float value[100];

   input();
   display();
  
}
/*
Function input() is used to input Barcode , Price and Quantity of the item and stores the value in their respective arrays.
*/
void input()
{
   printf(\"Grocery Store Inventory\ \");
   printf(\"=======================\ \");
   for(int i=0;i<100;i++)
   {
       printf(\"Barcode : \");
       scanf(\"%d\",&barcode);
       validate(barcode);
       arr1[i]=barcode;

       printf(\"\ Price : \");
       scanf(\"%f\",&price);
       arr2[i]=price;
       printf(\"\ Quantity : \");
       scanf(\"%d\",&qty);
       arr3[i]=qty;
       float inventory_value=calculate(price,qty);
       value[i]=inventory_value;
       total_inventory_value+=inventory_value;
   }  
}

/*
Function validate() is used to check if 0 value is not entered for the input barcode. If yes, it breaks the loop there itself.
*/

void validate(int b)
{
   if(barcode==0)
   {
       break;
   }
}

/*
Function calculate() is used to calculate the total inventory value
*/

float calculate(float p,int q)
{
  
   float total=p*q;
   return total;
}

/*
Function display() is used to display the output in specified format
*/

void display()
{
   printf(\"Goods in Stock\ \");
   printf(\"==============\ \");
   printf(\"Barcode \\t Price \\t Quantity \\t Value\");
   printf(\"\ -----------------------------------\ \");
   for(int i=0;i<100;i++)
   {
       printf(\"%d %f %d %f\",arr1[i],arr2[i],arr3[i],value[i]);
       printf(\"\ \");
   }
   printf(\"------\");
   printf(\"Total value goods in stock %f\",total_inventory_value);
}

THIS QUESTION IS FROM CHAPTER ARRAY AND LOOPS ***USE C LNAGUAGE ***i want to run this on matrix Design and code a program that lists the packaged goods in a gro
THIS QUESTION IS FROM CHAPTER ARRAY AND LOOPS ***USE C LNAGUAGE ***i want to run this on matrix Design and code a program that lists the packaged goods in a gro

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site