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

Write a program that contains the function calories() that is to accept a long i

ID: 3535893 • 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:

pizza--385 calories each slice

chips--170 calories each bag

apple--80 calories each

mustard--5 calories each tsp.

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

Explanation / Answer

#include<iostream.h>

void calories(int total,int *pizza,int *chips,int *apple,int*mustard);

void main()

{

int total;

int p=0,c=0,a=0,m=0;

cout<<"enter the total calaories ";

cin>>total;

calories(total,&p,&c,&a,&m);

cout<<"you can eat "<<p<<" slice of pizzas @ "<<p*385 <<" calaories";

cout<<" "<<c<<" bag of chips @ "<<c*170 <<" calaories";

cout<<" "<<a<<" apples @ "<<a*80 <<" calaories";

cout<<" "<<m<<" tsp musturd @ "<<m*30 <<" calaories";

}

void calories(int total,int *pizza,int *chips,int *apple,int*mustard)

{

if(total>385)

{

*pizza=total/385;

total=total-(385*(*pizza));

}

if(total>170)

{

*chips=total/170;

total=total-(170*(*chips));

}

if(total>80)

{

*apple=total/80;

total=total-(80*(*apple));

}

else

{

*mustard=total/30;

total=total-((*mustard)*30);

}

}

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