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