How to modify a code of grocery store


Assignment:

Q: Modify the existing code (separate attachment) to be more orderly in its output appearance. Basically so that the displays are similar to what is below in the samples.

Right now, I get this error when attempting to compile in Miracle C:

c:program filesmiracle cnewweek4.c: line 18: wrong # args in function call

'{ printf("Enter name for product %d: ",i+1)'

aborting compile

If I add in #include at the beginning, the program runs, but when it comes to the point where customer pick their products the display is very is disorganized and looks like this:

Products: n1. grapes:n2. corn:n3. oranges:n4. potatoes:n5. beans:nnSelect a product or 0 to complete

And once selecting 0 to complete checkout, it looks like this:checkoutn0

Purchase Total: 0.00nDiscount Total: 0.00nTotal Amount Due: 0.00nnThank you for shopping!nnC for checkout or X for exit:

I would to have it look like the samples below instead of strung out if possible and is there a way to get the "n" out of the display?

1) Include comments within the program to document the program internally.

2) Verify the program compiles and runs.

3) Thank you very much for your help.

Sample Inputs (customer inputs in red):

Enter name for product 1: grapes
Enter name for product 2: corn
Enter name for product 3: potatoes
Enter name for product 4: asparagus
Enter name for product 1: oranges

Enter per-pound price for Asparagus: $ 0.79
Enter per-pound price for Oranges: $ 1.29
Enter per-pound price for Potatoes: $ 4.99
Enter per-pound price for Corn: $ 1.09
Enter per-pound price for Grapes: $ 1.59

C for Checkout, X to exit: C

Products:

1. Asparagus
2. Oranges
3. Potatoes
4. Corn
5. Grapes

Select a product or 0 to complete checkout: 1

Enter the weight: 10

Products:

1. Asparagus
2. Oranges
3. Potatoes
4. Corn
5. Grapes

Select a product or 0 to complete checkout: 2

Enter the weight: 5.5

Products:

1. Asparagus
2. Oranges
3. Potatoes
4. Corn
5. Grapes

Select a product or 0 to complete checkout: 5

Enter the weight: 2.3

Products:
1. Asparagus
2. Oranges
3. Potatoes
4. Corn
5. Grapes

Select a product or 0 to complete checkout: 3

Enter the weight: 7

Products:
1. Asparagus
2. Oranges
3. Potatoes
4. Corn
5. Grapes

Select a product or 0 to complete checkout: 0

Purchase Total: $ 53.58
Discount Total: $ 2.68
Total Amount due: $ 50.90

C for Checkout, X to exit: X

#include

//Declare price as an array

float price[5];

//Declare the five produce items
char vegetables[5][20] ;
float weight;
float purchase_total;
float discount_total;
int i;

//Customers are prompted to enter the price per pound for each of the five produce items.
void prompt(){
//Code modified to prompt user to enter five products
printf("Enter 5 product names firstn");
for(i=0;i<5;i++)
{
printf("Enter name for product %d: ",i+1);
scanf("%s",vegetables[i]);
}
printf("n");
for(i=0;i<5; i++)
{
printf("Enter per pound price for %s: ",vegetables[i]);
scanf("%f", &price[i]);
}
}

void checkout(){
int product;
purchase_total = 0;
//Customers select produce from menu list or 0 to complete checkout process.
do{
//Display the five produce items which customers will select from.
//Selections stored in the array.
printf("Products: n");
for(i=0;i<5;i++)
printf("%d. %s:n",i+1,vegetables[i]);

printf("nSelect a product or 0 to complete checkoutn");
scanf("%d", &product);

if (product == 0) break;

//Prompt customer to input the weight of the produce product selected.
printf("Enter the weight (in pounds)n");
scanf("%f", &weight);

//Calculate the total purchase amount.
purchase_total = purchase_total + (price[product-1] * weight) ;

} while(product != 0);

}

int main()
{
char choice;
prompt();

//Program loops until customer selects option to end.
do{
printf("nC for checkout or X for exit: ");
scanf(" %c",&choice);
if (toupper(choice) == 'X')
{
return 0;
}
else if (toupper(choice) == 'C')
{
checkout();
//Display the total purchase amount as "Purchase Total:".
printf ("Purchase Total: %.2fn", purchase_total) ;

//If the total purchase is equal to or greater than 50.01, apply a 5% discount to the total and display the discount amount as "Discount Total:".
//initialize the discount total to 0 to avoid misleading information if purchase_total < 50.01.
discount_total = 0;

//If total purchase is equal to or greater than 50.01, apply a 5% discount to the total amount and display the discount amount as "Discount Total:".
if (purchase_total >= 50.01 )
discount_total = purchase_total * 0.05 ;

printf ("Discount Total: %.2fn", discount_total) ;
purchase_total = purchase_total - discount_total ;

//Display the purchase total including the discount if applicable as "Total Amount Due:"
printf ("Total Amount Due: %.2fn", purchase_total) ;

// The header line is printed here.
printf("nThank you for shopping!n");
}
else
{
//If choice other than C or X is selected:"
printf("nInvalid Entryn");
}
//Program will loop until X is entered to exit.
}while(1);

return 0;

}

Solution Preview :

Prepared by a verified Expert
C/C++ Programming: How to modify a code of grocery store
Reference No:- TGS01936409

Now Priced at $30 (50% Discount)

Recommended (97%)

Rated (4.9/5)