Question

In: Computer Science

A bag of cookies contains 40 cookies. The calorie information printed on the bag claims that...

A bag of cookies contains 40 cookies. The calorie information printed on the bag claims that there are 8 servings in each bag and that a single serving equals 300 calories. Design and write a C++ program that prompts your user for the number of cookies that he or she ate and then displays the calories they consumed.

Use variables to represent the given information, such as the number of cookies in each bag and the number of calories in each serving. Compose statements using the given variables to calculate the number of calories in each cookie. Use the number of cookies and the number of calories per cookie to determine how many calories were consumed. The use of magic is not permitted in computer programming. You, as the programmer must compose steps that store given information in variables and then use these variables to determine values such as the number of calories in each cookie.

CODE IN C++

Solutions

Expert Solution

Answer-

Your code is given below As the requirement-

#include<iostream>
using namespace std;

int Cookies_Function() {
int Num_cookies;

cout << "Enter how many cookies you consume?" << '\n';
cin >> Num_cookies; //take input

return Num_cookies;
}

double total_calories(int Num_cookies) {
double cookies_per_serving = 40 / 8; // 8 servings in each bag
double calories_per_serving = 300; //single serving equals 300 calories
double total_consumed_cookies = Num_cookies / cookies_per_serving * calories_per_serving;

return total_consumed_cookies;
}

int main() {
int Num_cookies = Cookies_Function();
double total_consumed_cookies = total_calories(Num_cookies);

cout << "======== you consumed :-" <<" "<< total_consumed_cookies << " calories===========." << '\n'; //display the output
return 0;
}

Screenshot of output:

Note- Please do upvote, if any problem then comment in box sure I will help.


Related Solutions

A bag of cookies holds 40 cookies and these 40 cookies represent 10 servings, then how...
A bag of cookies holds 40 cookies and these 40 cookies represent 10 servings, then how many cookies can you eat in 1 serving? List 4 principles of OOP and discuss why they are important to OOP.
A manufacturer claims that each bag of their chocolate covered pretzels contains at least 9 red...
A manufacturer claims that each bag of their chocolate covered pretzels contains at least 9 red chocolate covered pretzels. A sample of 25 bags of these pretzels yields an average of 8 red chocolate covered pretzels with a sample standard deviation of 0.7 .Test their claim at a 5% significance level. (State the null and alternative hypotheses. Be sure to clearly state the “rejection region” for the test, and state your conclusion in words.)
A bag contains 40 jellybeans with 5 different colors. Each color is equally represented. You are...
A bag contains 40 jellybeans with 5 different colors. Each color is equally represented. You are interested in randomly drawing one jellybean at a time and checking the color before eating it. You want to know how many red jelly beans you will pull out of the bag during the first 10 draws. Can the probability be found by using the binomial probability formula? Why or why not? No. The trials are fixed, but the events are independent. Yes. The...
Bowl 1 contains 30 vanilla cookies and 10 chocolate cookies. What is the likelihood of the...
Bowl 1 contains 30 vanilla cookies and 10 chocolate cookies. What is the likelihood of the following: you, without looking, select a vanilla cookie and eat it (i.e. you are selecting without replacement), then select a chocolate cookie, and eat it, and then select a vanilla cookie. Now, what is the likelihood if instead you had a Bowl 2 which contains 20 of each.
A cookie jar contains 15 chocolate chip and 5 oatmeal cookies. If 3 cookies are randomly...
A cookie jar contains 15 chocolate chip and 5 oatmeal cookies. If 3 cookies are randomly selected,what is the probability at least one is an oatmeal cookie? (Find two methods to solve)
Bowl 1 contains 30 vanilla cookies and 10 chocolate cookies. What is the likelihood of choosing...
Bowl 1 contains 30 vanilla cookies and 10 chocolate cookies. What is the likelihood of choosing 15 vanilla and 10 chocolate cookies (without replacement). Now, instead, what is the likelihood of choosing 15 vanilla and 10 chocolate cookies (without replacement) if you had Bowl 2 which contains 20 of each.
A package of a certain type of cookies claims that there are about 11 grams of...
A package of a certain type of cookies claims that there are about 11 grams of sugar in a single cookie. Evaluate the validity of this claim based on a sample of 14 randomly chosen cookies which had the mean value of 11.2g of sugar with standard deviation 0.3g. Use α = 0.05 significance level
A package of a certain type of cookies claims that there are about 11 grams of...
A package of a certain type of cookies claims that there are about 11 grams of sugar in a single cookie. Evaluate the validity of this claim based on a sample of 14 randomly chosen cookies which had the mean value of 11.2g of sugar with standard deviation 0.3g. Use α = 0.05 significance level. a. State the hypotheses and identify the claim. b. Compute the test value. c. Find the critical value. d. Make the decision to reject or...
The number of chocolate chips in a bag of chocolate chip cookies is approximately normally distributed...
The number of chocolate chips in a bag of chocolate chip cookies is approximately normally distributed with mean 1263 and a standard deviation of 118. ​(a) Determine the 29th percentile for the number of chocolate chips in a bag. ​(b) Determine the number of chocolate chips in a bag that make up the middle 97% of bags. ​(c) What is the interquartile range of the number of chocolate chips in a bag of chocolate chip​ cookies?
The number of chocolate chips in a bag of chocolate chip cookies is approximately normally distributed...
The number of chocolate chips in a bag of chocolate chip cookies is approximately normally distributed with mean 1261 and a standard deviation of 118. ​(a) Determine the 28th percentile for the number of chocolate chips in a bag. ​(b) Determine the number of chocolate chips in a bag that make up the middle 96​% of bags. ​(c) What is the interquartile range of the number of chocolate chips in a bag of chocolate chip​ cookies?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT