fork download
  1. // Torrez, Elaine CS1A Chapter 5 P. 294, #4
  2.  
  3. /******************************************************************************************
  4.  *
  5.  * Calories Burned on Treadmill
  6.  *
  7.  * --------------------------------------------------------------------------------
  8.  * This program calculates and displays the number of calories burned after a set
  9.  * number of minutes on a treadmill. The treadmill burns 3.9 calories per minute.
  10.  * The program uses a loop to display the calories burned after 10, 15, 20, 25,
  11.  * and 30 minutes.
  12.  * --------------------------------------------------------------------------------
  13.  *
  14.  * INPUT
  15.  * minutes : Number of minutes (loop variable, 10 to 30 in steps of 5)
  16.  * caloriesPerMinute : Constant rate of calories burned (3.9 calories per minute)
  17.  *
  18.  * OUTPUT
  19.  * caloriesBurned : Calories burned at each time interval
  20.  *
  21.  *******************************************************************************************/
  22.  
  23. #include <iostream>
  24. #include <iomanip>
  25. using namespace std;
  26.  
  27. int main ()
  28. {
  29. const double caloriesPerMinute = 3.9; // Calories burned per minute
  30. double caloriesBurned; // OUTPUT - Total calories burned
  31. int minutes; // Loop variable
  32.  
  33. cout << "Minutes\tCalories Burned" << endl;
  34. cout << "-------------------------" << endl;
  35.  
  36. // Loop to calculate calories burned at each interval
  37. for (minutes = 10; minutes <= 30; minutes += 5)
  38. {
  39. caloriesBurned = minutes * caloriesPerMinute;
  40. cout << setw(4) << minutes << "\t\t" << fixed << setprecision(1)
  41. << caloriesBurned << endl;
  42. }
  43.  
  44. return 0;
  45. }
  46.  
Success #stdin #stdout 0.01s 5272KB
stdin
Standard input is empty
stdout
Minutes	Calories Burned
-------------------------
  10		39.0
  15		58.5
  20		78.0
  25		97.5
  30		117.0