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

Write a program that includes a function picnic() that will accept a floating-po

ID: 3768997 • Letter: W

Question

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

#include <stdio.h>

void picnic(int ,int*,int*,int*,int*);

int main(void) {

int hotdogs, hamburgers, salad, pickles;
float num1;
printf("Enter the amount of money:");
scanf("%f",&num1);
picnic(num1*100., &hotdogs, &hamburgers, &salad, &pickles);
return 0;
}

void picnic(int x, int *hotdogs, int *hamburgers, int *salad, int *pickles) {
*hotdogs=x/100;
printf("The number of hotdogs is %3d ", *hotdogs);
x=x%100;
*hamburgers =x/50;
printf("The number of hamburgers is %3d ", *hamburgers);
x=x%50;
*salad = x/25;
printf("The number of salad is %3d ", *salad);
x=x%25;
*pickles=x;
printf("The number of pickles is %3d ", *pickles);
return;

}

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