fork download
  1. //Charlotte Davies-Kiernan CS1A Chapter 3 P.144 #7
  2. //
  3. /*****************************************************************************
  4.  *
  5.  * Compute Amount of Calories
  6.  * ___________________________________________________________________________
  7.  * This program will calculate the amount of calories the user ate by asking
  8.  * the amount of cookies they ate and with knowing the amount of calories
  9.  * per cookie
  10.  *
  11.  * The formulas that will be used:
  12.  * cookies per serving = total cookies / servings
  13.  * calories per cookie = total cookies / servings
  14.  * calories eaten = cookies eaten * calories per cookie
  15.  * __________________________________________________________________________
  16.  * INPUT
  17.  * cookiesEaten // Amount of cookies eaten by user
  18.  * totalCookies // Amount of cookies in the package
  19.  * servings // Amount of servings in the package
  20.  * caloriesPerServing // Amount of calories per serving
  21.  * caloriesPerCookie // Amount of calories per cookie
  22.  * cookiesPerServing // Amount of cookies in a serving
  23.  *
  24.  * OUTPUT
  25.  * caloriesEaten //Total amount of calories eaten based on user's input
  26.  ****************************************************************************/
  27. #include <iostream>
  28. #include <iomanip>
  29. using namespace std;
  30. int main()
  31. {
  32. int caloriesEaten; //OUTPUT - total amount of calories eaten
  33. int caloriesPerCookie; //INPUT - amount of calories per cookie
  34. int caloriesPerServing; //INPUT - amount of calories per serving
  35. int cookiesEaten; //INPUT - amount of cookies user has eaten
  36. int cookiesPerServing; //INPUT - amount of cookies in a serving
  37. int servings; //INPUT - amount of servings in the package
  38. int totalCookies; //INPUT - amount of cookies in the package
  39. //
  40. // User input
  41. cin >> cookiesEaten;
  42. //
  43. //Variables
  44. totalCookies = 40;
  45. servings = 10;
  46. caloriesPerServing = 300;
  47. //
  48. //Calculate Calories
  49. cookiesPerServing = totalCookies / servings;
  50. caloriesPerCookie = caloriesPerServing / cookiesPerServing;
  51. caloriesEaten = cookiesEaten * caloriesPerCookie;
  52. //
  53. //Display to User
  54. cout << "You consumed " << caloriesEaten << " calories.";
  55. return 0;
  56. }
Success #stdin #stdout 0.01s 5288KB
stdin
19
stdout
You consumed 1425 calories.