write a program that contains the function calories() that is to accept a long i
ID: 3644486 • Letter: W
Question
write a program that contains the function calories() that is to accept a long integer number total and the address of the integer variables pizza, chips, apples, mustard. the passed long integer represents the total number of calories you are able to consume in this meal and the function is to determine the number of calories in slices of pizza, chips, apples, and teaspoons of mustard, in the passed value, writing these values directly into the respective variables declared in the calling function.the function will be called from the main program and when it returns to main, it will print out variables pizza, chips, apples, mustard... the calories for food are following:
pizza, 385 per slice, chips, 170 per bag, apple, 80 each, mustard, 5 per tbsp.
Explanation / Answer
here you go:
void calories(long total, int *pizza,int *chips,int *apples, int *mustard) // function
{
int pizza_cal = 385 * pizza;
int chips_cal = 170 * chips;
int apples_cal = 80 * apples;
int mustard_cal = 5 * mustard;
long total = pizza_cal + chips_cal + apples_cal + mustard_cal;
printf(" The total calories consumed : %ld ",total);
printf(" Individual calories__ pizza : %d, chips : %d, apples : %d, mustard : %d",pizza_cal,chips_cal,apples_cal,mustard_cal);
} // end of function calories
main()
{
int pizza = 2; int chips = 3, int apples = 1 , int mustard = 4;
calories(0,&pizza,&chips,&apples,&mustard);
} // end of main
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.