fork download
  1. //Cecilia Rangel CSC5 Chapter 3, P. 144, #7
  2. //
  3. /**************************************************************
  4.  *
  5.  * Computes calories eaten
  6.  * ____________________________________________________________
  7.  * This program calculates how many calories the user has eaten
  8.  * by how many cookies they ate.
  9.  *
  10.  * Calculation is based on this Formula:
  11.  * 1 serving= 300 calaries
  12.  *___________________________________________________________
  13.  * INPUT
  14.  * cookiesEaten : user input
  15.  * cookiesInBag : 40 cookies
  16.  * servingsInBag : 10 servings
  17.  * caloriesPerServing: 300 Calories
  18.  *
  19.  * OUTPUT
  20.  * caloriesConsumed : Amount of calories the user ate
  21.  *
  22.  **************************************************************/
  23. #include <iostream>
  24. using namespace std;
  25.  
  26. int main() {
  27. float cookiesEaten;
  28. float cookiesInBag;
  29. float servingsInBag;
  30. float caloriesPerServing;
  31. float cookiesPerServing;
  32. float caloriesPerCookie;
  33. float caloriesConsumed;
  34.  
  35.  
  36.  
  37. cookiesInBag = 40;
  38. servingsInBag = 10;
  39. caloriesPerServing = 300;
  40.  
  41.  
  42.  
  43. cookiesPerServing = cookiesInBag / servingsInBag;
  44. caloriesPerCookie = caloriesPerServing / cookiesPerServing;
  45.  
  46.  
  47.  
  48. cout << "How many cookies did you eat?" << endl;
  49. cin >> cookiesEaten;
  50.  
  51.  
  52.  
  53. caloriesConsumed = cookiesEaten * caloriesPerCookie;
  54.  
  55.  
  56.  
  57. cout << "You ate " << caloriesConsumed << " calories.";
  58. return 0;
  59. }
Success #stdin #stdout 0s 5324KB
stdin
28
stdout
How many cookies did you eat?
You ate 2100 calories.