Write a program that includes a function picnic() that will accept a floating-po
ID: 3864473 • 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
// C code
#include <stdio.h>
#include <stdlib.h>
void picnic(int total, int *hotdogs, int *hamburgers, int *salad, int *pickles)
{
*hotdogs=total/100;
total=total%100;
*hamburgers =total/50;
total=total%50;
*salad = total/25;
total=total%25;
*pickles=total;
printf("Hotdogs: %3d ", *hotdogs);
printf("Hamburgers: %3d ", *hamburgers);
printf("Salad: %3d ", *salad);
printf("Pickles: %3d ", *pickles);
}
int main()
{
int hotdogs, hamburgers, salad, pickles;
float total;
printf("Enter the totat: ");
scanf("%f",&total);
picnic(total*100, &hotdogs, &hamburgers, &salad, &pickles);
return 0;
}
/*
output:
Enter the totat: 3.78
Hotdogs: 3
Hamburgers: 1
Salad: 1
Pickles: 3
*/
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.