fork download
  1. #include <iostream>
  2. #include <iomanip> // For setting decimal precision
  3.  
  4. using namespace std;
  5.  
  6. /*
  7.  * Program Description:
  8.  * This program calculates the number of calories burned while running on a treadmill.
  9.  * The rate of calorie burn is 3.9 calories per minute.
  10.  * The program will display the calories burned after running for 10, 15, 20, 25, and 30 minutes.
  11.  * The results are displayed with two decimal points of precision.
  12.  */
  13.  
  14. int main() {
  15. // Define the rate of calories burned per minute
  16. const double caloriesPerMinute = 3.9;
  17.  
  18. // Array of times in minutes for which we want to calculate calories burned
  19. int times[] = {10, 15, 20, 25, 30};
  20.  
  21. // Loop through each time value and calculate calories burned
  22. cout << "Calories burned after running on the treadmill for different times:\n";
  23. cout << fixed << setprecision(2); // Format output to 2 decimal places
  24.  
  25. // Display the number of calories burned for each time interval
  26. for (int i = 0; i < 5; i++) {
  27. // Calculate calories burned for the current time interval
  28. double caloriesBurned = times[i] * caloriesPerMinute;
  29.  
  30. // Display the result
  31. cout << "After " << times[i] << " minutes: " << caloriesBurned << " calories burned.\n";
  32. }
  33.  
  34. cout << "\nEnd of program." << endl;
  35. return 0;
  36. }
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
Calories burned after running on the treadmill for different times:
After 10 minutes: 39.00 calories burned.
After 15 minutes: 58.50 calories burned.
After 20 minutes: 78.00 calories burned.
After 25 minutes: 97.50 calories burned.
After 30 minutes: 117.00 calories burned.

End of program.