Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I attached the question,my solution and my error. It is not an wrror actually bu

ID: 3581886 • Letter: I

Question

I attached the question,my solution and my error. It is not an wrror actually but my teacher didn't accept it as I used break. Please edit my solution and fix my error. THANKS

question:

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:

my solution:

#include <stdio.h>

#define MAX 5

void printInventory(int barcode[], float price[], int quantity[]);

void printInventory (int barcode[], float price[], int quantity[])

{

int i;

float value[MAX];

double sum=0;

for (i = 0; i < MAX; i++) {

   printf("%d",quantity[i]);

value[i] = price[i] * quantity[i];

sum+=value[i];

}

printf(" Goods in Stock ");

printf("============== ");

printf("Barcode Price Quantity Value ");

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

{

   if(barcode[i]==0)

   break;

printf("%d $%.2f %d $%.2f ", barcode[i],price[i],quantity[i],value[i]);

       }

       printf(" ------ ");

       printf("Total value goods in stock %.2f",sum);

}

int main() {

int barcode[MAX], quantity[MAX], i;

float price[MAX];

for (i = 0; i < MAX; i++) {

printf("Barcode: ");

scanf("%d", &barcode[i]);

if(barcode[i]==0)

{

   break;

       }

       else

       {

   printf("Price: ");

scanf("%f", &price[i]);

printf("Quantity: ");

scanf("%d", &quantity[i]);

       }

}

int j;

for( j=0;j<MAX;j++)

{

   printf("%d",quantity[j]);

       }

printInventory(barcode, price, quantity);

return 0;

}


MY ERROR:

You are not allowed to use break statement to control loops


       if (barcode[i] == 0)
       {
           break;
       }

Explanation / Answer

#include <stdio.h>
#define MAX 5

void printInventory (int barcode[], float price[], int quantity[]) {
   int i=0;
   float value[MAX];
   double sum=0;

   printf(" Goods in Stock ");
   printf(" ============== ");
   printf("Barcode Price Quantity Value ");
   do {
       value[i] = price[i] * quantity[i];
       sum+=value[i];
       printf("%d $%.2f %d $%.2f ", barcode[i],price[i],quantity[i],value[i]);
} while((barcode[i]!=0) && (i++<MAX));

   printf(" ------ ");
printf("Total value goods in stock %.2f",sum);
   printf(" ");
}

int main() {
   int barcode[MAX], quantity[MAX], i=0;
   float price[MAX];
   do {
       printf("Barcode: ");
       scanf("%d", &barcode[i]);
       if (barcode[i]==0)
        continue;
printf("Price: ");
       scanf("%f", &price[i]);
       printf("Quantity: ");
       scanf("%d", &quantity[i]);
   } while((barcode[i]!=0) && (i++<MAX));
   printInventory(barcode, price, quantity);
   return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote