fork download
  1. // Nicolas Ruano CS1A Chapter 3 Pp. 144 # 7
  2. /******************************************************************************
  3.  * SOLVING AVERAGE CALORIES
  4.  * ____________________________________________________________________________
  5.  * INPUT
  6.  * Cookies per bag = 40
  7.  * Servings per bag = 10
  8.  * Calories per serving = 300
  9.  * ____________________________________________________________________________
  10.  * PROCESSING
  11.  * caloriesPerCookie = (CALORIES_PER_SERVING * SERVINGS_PER_BAG) / COOKIES_PER_BAG
  12.  * results for cookies eaten: 5
  13.  * ____________________________________________________________________________
  14.  * OUTPUT
  15.  * totalCalories = cookiesEaten * caloriesPerCookie
  16.  *
  17.  * Results = 375 calories
  18.  *****************************************************************************/
  19. #include <iostream>
  20. using namespace std;
  21.  
  22. int main() {
  23. const int COOKIES_PER_BAG = 40;
  24. const int SERVINGS_PER_BAG = 10;
  25. const int CALORIES_PER_SERVING = 300;
  26.  
  27. // Calculate calories per cookie
  28. int caloriesPerCookie = (CALORIES_PER_SERVING * SERVINGS_PER_BAG) / COOKIES_PER_BAG;
  29.  
  30. int cookiesEaten;
  31. cout << "How many cookies did you eat? R:/ 5 cookies\n";
  32. cin >> cookiesEaten;
  33.  
  34. int totalCalories = cookiesEaten * caloriesPerCookie;
  35.  
  36. cout << "You consumed approximately 375" << totalCalories << " calories." << endl;
  37.  
  38. return 0;
  39. }
  40.  
Success #stdin #stdout 0.01s 5280KB
stdin
Standard input is empty
stdout
How many cookies did you eat? R:/ 5 cookies
You consumed approximately 3752457375 calories.