In: Computer Science
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;
}
#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;
}
