Write a program that contains the function calories() that is to accept a long i
ID: 3540872 • Letter: W
Question
Write a program that contains the function calories() that is to accept a long integer number total and the addresses of the integer variables pizza, chips, apples, and 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, bags of chips, apples, and teaspoons of mustard in the passed value, 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 variables pizza, chips, apples, and mustard.
The calories in our favorite foods are in this order:class="c1">
pizza--385 calories each sliceclass="c5">
class="c5">
chips--170 calories each bagclass="c5">
apple--80 calories eachclass="c5">
class="c5">
mustard--5 calories each tsp.class="c5">
For example, if I enter a total amount of calories of 1050, I can eat:
2 slices pizza @ 770 calories (1050 - 770 = 280 calories remain)
1 bag of chips @ 170 calories (280 - 170 = 110 calories remain)
1 apple @ 80 calories (110 - 80 = 30 calories remain)
6 tsp. mustard @ 30 calories
class="c1">
Explanation / Answer
please rate - thanks
if you don't normally use getch() and include <conio.h> just remove them
any questions ask
#include <stdio.h>
#include <conio.h>
void calories(long,int*,int*,int*,int*);
int main()
{long tcalories;
int pizza,chips,apple,mustard;
printf("Enter number of calories: ");
scanf("%ld",&tcalories);
calories(tcalories,&pizza,&chips,&apple,&mustard);
printf("You can eat %d slices pizza %d bag(s) of chips %d apple(s) %d tsp. mustard ",
pizza,chips,apple,mustard);
getch();
return 0;
}
void calories(long tcalories,int* pizza,int* chips,int* apple,int* mustard)
{int pizzaCalorie=385,chipCalorie=170,appleCalorie=80,mustardCalorie=5;
*pizza=tcalories/pizzaCalorie;
tcalories%=pizzaCalorie;
*chips=tcalories/chipCalorie;
tcalories%=chipCalorie;
*apple=tcalories/appleCalorie;
*mustard=tcalories%appleCalorie/mustardCalorie;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.