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

Please write this program and explain what each line of code is doing in the pro

ID: 3731848 • Letter: P

Question

Please write this program and explain what each line of code is doing in the program. this needs to be in basic C programming

Write a program that includes a function picnic() that will accept a floating-point number total and the addresses of the integer variables hotdogs, hamburgers, salad, pickles. The passed floating-point number represents the total amount of money to be spent on food. The function is to determine the quantity of hotdogs, hamburgers, salad, and pickles that can be purchased, writing these values directly into the respective variables declared in the calling function.

This function will be called from the main program and when it returns to main, it will print out the values of hotdogs, hamburgers, salad, and pickles.

Our favorite foods are in this order:

hot dogs--$1.00 each

hamburgers--$0.50 each

salad--$0.25 each

pickles--$0.01 each

For example, if I enter a total amount of money of $3.78, I can bring the following items to my picnic:

3 hot dogs

1 hamburger

1 salad

3 pickles

Explanation / Answer


/**
To solve this problem you need to use call by reference, in place of passing variables pass their address
And any change to that variable modify that at it's address.

So in function I passed their address using & ampersand , then getting value in function using *(pointer).

Calculation Process:

1. Find the quantity by dividing total amount by it's price

2. Calculating remaining total by formula total=total-(quantity*price)

3. Repeat step 1 & 2 for all

Sample Input/Output:

hot dogs--$1.00 each
hamburgers--$0.50 each
salad--$0.25 each
pickles--$0.01 each

Enter your total amount:3.78

You can bring the following items

3 hot dogs

1 hamburger

1 salad

2 pickles*/


//Please create .c file and copy code from below line to the end of answer

#include<stdio.h>

//function to distribute total among all items
void picnic(float total,int *hotdogs, int *hamburger, int *salad,int *pickles)
{
//First assign the value to hotdogs by dividing total by hot dogs rate
*hotdogs=total/1;

//Calculating remaining balance by subtracting hot dogs total amount
total=total-(*hotdogs *1);

//Calculating hamburgers quantity
*hamburger=total/0.50;

//Calculating remaining
total=total-(*hamburger*0.50);

//Calculating salad quantity
*salad=total/0.25;

//Calculating remaining
total=total-(*salad*0.25);

//Calculating pickles quantity
*pickles=total/0.01;

}
int main()
{
//Declaring float variables
float total;
//Declaring integer variables
int hotdogs=0, hamburger=0, salad=0, pickles=0;

//Displaying menu
printf("hot dogs--$1.00 each ");

printf("hamburgers--$0.50 each ");

printf("salad--$0.25 each ");

printf("pickles--$0.01 each ");
//Asking user to enter total amount
printf("Enter your total amount:");
scanf("%f",&total);

//calling function along with 5 parameters
picnic(total,&hotdogs, &hamburger, &salad, &pickles);

//Displaying the output
printf(" You can bring the following items ");
printf(" %d hot dogs ",hotdogs);
printf(" %d hamburger ",hamburger);
printf(" %d salad ",salad);
printf(" %d pickles ",pickles);

return 0;
}