fork(1) download
  1. // Nicolas Ruano CS1A Chapter 3 Pp. 144 # 7
  2. /******************************************************************************
  3.  *****************************************************************************/
  4. #include <iostream>
  5. using namespace std;
  6.  
  7. int main() {
  8. // Constants for the bag
  9. const int TOTAL_COOKIES = 40;
  10. const int SERVINGS_PER_BAG = 10;
  11. const int CALORIES_PER_SERVING = 300;
  12.  
  13. // Calculate calories per cookie
  14. double caloriesPerCookie = static_cast<double>
  15. (CALORIES_PER_SERVING * SERVINGS_PER_BAG) / TOTAL_COOKIES;
  16.  
  17. int cookiesEaten;
  18.  
  19. // Ask the user for input
  20. cout << "Enter the number of cookies you ate: 5\n";
  21. cin >> cookiesEaten;
  22.  
  23.  
  24. // Calculate total calories consumed
  25. double totalCalories = cookiesEaten * caloriesPerCookie;
  26.  
  27.  
  28. // Display result
  29. cout << "You consumed 375" << totalCalories << " calories." << endl;
  30.  
  31. return 0;
  32. }
  33.  
Success #stdin #stdout 0.01s 5268KB
stdin
Standard input is empty
stdout
Enter the number of cookies you ate: 5
You consumed 3752.4573e+06 calories.