// Torrez, Elaine CS1A Chapter 3 P. 144, #7
/******************************************************************************************
*
* CALCULATE CALORIES CONSUMED
*
* --------------------------------------------------------------------------------
* This program asks the user to enter how many cookies he or she ate.
* Each bag holds 40 cookies, with 10 servings per bag, and each serving equals
* 300 calories. The program calculates and displays the total calories consumed.
* --------------------------------------------------------------------------------
*
* INPUT
* cookiesEaten : Number of cookies eaten by the user
*
* OUTPUT
* totalCalories : Total calories consumed
*
*******************************************************************************************/
#include <iostream>
#include <iomanip>
using namespace std;
int main ()
{
// Constants
const int COOKIES_PER_BAG = 40; // Number of cookies in one bag
const int SERVINGS_PER_BAG = 10; // Servings per bag
const int CALORIES_PER_SERVING = 300; // Calories per serving
// Variables (ABC order)
int cookiesEaten; // INPUT number of cookies eaten
double totalCalories; // OUTPUT total calories consumed
// Ask user for input
cout << "Enter the number of cookies you ate: ";
cin >> cookiesEaten;
// Calculate calories per cookie
double caloriesPerCookie = static_cast<double>(CALORIES_PER_SERVING) /
(COOKIES_PER_BAG / SERVINGS_PER_BAG);
// Calculate total calories consumed
totalCalories = cookiesEaten * caloriesPerCookie;
// Display result
cout << fixed << setprecision(0); // Display whole number calories
cout << "\nYou consumed " << totalCalories << " calories." << endl;
return 0;
}