fork(1) download
  1. // Nicolas Ruano CS1A
  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. // Calculate total calories consumed
  22. double totalCalories = cookiesEaten * caloriesPerCookie;
  23.  
  24. // Display result
  25. cout << "You consumed 375" << totalCalories << " calories." << endl;
  26.  
  27. return 0;
  28. }
  29.  
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
Enter the number of cookies you ate: 5
You consumed 3752.45752e+06 calories.