Question

In: Computer Science

Why is my C++ program not calculating number of servings and total calories consumed. one serving...

Why is my C++ program not calculating number of servings and total calories consumed.

one serving is 3 Oreo cookies and one serving is 53 calories.

I need to use floating point arithmetic.

#include <iostream>
using namespace std;

int main()
{
//Declaring constants.
float SERVING = 3;
float CALORIES = 53;

// Declaring variables.
int cookies;
int totalCalories;
int TotalServings;

//Calculate number of servings consumed.
TotalServings = cookies / SERVING;

// Calculate total Calories consumed.
totalCalories = TotalServings * CALORIES;

//Prompt the user to enter the number of cookies consumed.
cout << "Hi there! I will determine how many servings"
<< " and calories you have consumed." << endl;
cout << "How many whole cookies have you eaten?: ";
cin >> cookies;

//Display the number of servings the user has
//eaten and the total calories consumed.
cout << cookies <<" Oreos is equal to "
<< TotalServings << " servings!" << endl;
cout << "You have consumed " << totalCalories
<< " calories. Stop eating cookies!" << endl;

}

Solutions

Expert Solution

#include <iostream>

using namespace std;

int main() {
//Declaring constants.
    float SERVING = 3;
    float CALORIES = 53;

// Declaring variables.
    int cookies;
    int totalCalories;
    int TotalServings;

//Prompt the user to enter the number of cookies consumed.
    cout << "Hi there! I will determine how many servings"
         << " and calories you have consumed." << endl;
    cout << "How many whole cookies have you eaten?: ";
    cin >> cookies;

    //Calculate number of servings consumed.
    TotalServings = cookies / SERVING;

// Calculate total Calories consumed.
    totalCalories = TotalServings * CALORIES;

//Display the number of servings the user has
//eaten and the total calories consumed.
    cout << cookies << " Oreos is equal to "
         << TotalServings << " servings!" << endl;
    cout << "You have consumed " << totalCalories
         << " calories. Stop eating cookies!" << endl;

}


Related Solutions

What is the correlation between the number of calories consumed and BMI? What is the slope...
What is the correlation between the number of calories consumed and BMI? What is the slope coefficient for the linear relationship between the number of calories consumed and BMI, assuming that caloric intake is the independent variable? Round answer to 3 decimal places. What is the intercept for the linear relationship between the number of calories consumed and BMI, assuming caloric intake is the independent variable? Which of the following can you conclude based on your analyses?a) consumption of more...
The Decadent Desserts cookbook has recipes for desserts. The number of calories per serving for the...
The Decadent Desserts cookbook has recipes for desserts. The number of calories per serving for the recipes in the cookbook is normally distributed with a mean of 378 and a standard deviation of 34.5. If 18 recipes are randomly selected to serve at a reception, what is the probability that the average calories per serving for the sample is over 385?
The file Cereals contains the calories and sugar, in grams, in one serving of seven breakfast...
The file Cereals contains the calories and sugar, in grams, in one serving of seven breakfast cereals: Cereal                                                             Calories                             Sugar Kellogg’s all Bran                                         80                                       6 Kellogg’s Corn Flakes                                  100                                     2 Wheaties                                                        100                                     4 Nature’s path Organic Multigrain Flakes 110                                     4 Kellogg’s rice Krispies                                 130                                     4 Post Shredded Wheat Vanilla almond       190                                     11 Kellogg’s Mini Wheats                                200                                     10 a. Compute and interpret the coefficient of correlation, r. b. at the 0.05 level of...
Orville redenbacher states that the average number of calories in a serving of popcorn is 120 with a standard deviation of 15.
Orville redenbacher states that the average number of calories in a serving of popcorn is 120 with a standard deviation of 15. a nutritionist claims a serving of popcorn is less than 120 calories. he selects 42 different popcorn samples and finds the average calories to be 115 calories per serving. check the nutritionist claim at a=0.01
A cereal company has claimed that one serving of their cereal has on average 120 calories...
A cereal company has claimed that one serving of their cereal has on average 120 calories with a standard deviation of 12 calories.  You decide to test their claims and examine 10 different recommended serving sized bowls for calorie count and nutritional content. The data is below.  With an alpha level of .05, does the evidence support the cereal company’s claims?   α = .05 μ = 120 σ = 12 mean = _____ n = _____ Bowls 1 2 3 4 5...
C LANGUAGE ONLY Write a C program to count the total number of duplicate elements in...
C LANGUAGE ONLY Write a C program to count the total number of duplicate elements in an array. Enter the number of elements to be stored in the array: 3 Input 3 elements in the arrangement: element [0]: 5 element [1]: 1 element [2]: 1 Expected output: The total number of duplicate elements found in the array is: 1
Number guessing Game (20 Marks) Write a C program that implements the “guess my number” game....
Number guessing Game Write a C program that implements the “guess my number” game. The computer chooses a random number using the following random generator function srand(time(NULL)); int r = rand() % 100 + 1; that creates a random number between 1 and 100 and puts it in the variable r. (Note that you have to include <time.h>) Then it asks the user to make a guess. Each time the user makes a guess, the program tells the user if...
2. If total utility is not listed in a chart showing the number of apples consumed...
2. If total utility is not listed in a chart showing the number of apples consumed a. it is impossible to determine. b. it can be indirectly calculated by looking at total costs. c. it still can be determined by adding the sums of all the marginal utilities. d. both b) and c) are correct. 3. The rational economic being who compares costs and benefits a. does not think about the marginal costs and benefits, only the total costs and...
In C programming language, write the program "3x3" in size, calculating the matrix "c = a...
In C programming language, write the program "3x3" in size, calculating the matrix "c = a * b" by reading the a and b matrices from the outside and writing on the screen?
IN BASIC C# If It Fits, It Ships! OVERVIEW In this program you will be calculating...
IN BASIC C# If It Fits, It Ships! OVERVIEW In this program you will be calculating the total amount the user will owe to ship a rectangular package based on the dimensions and we will add in insurance based on the prices of the items inside of the package.. INSTRUCTIONS: 1. Welcome the user and explain the purpose of the program. 2. In the Main, prompt the user for the width, length and height of their package. a. Each of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT