//Nicolas Ruano CS1A Chapter 5, P. 294, #4
/**************************************************************
*
* COMPUTES AND DISPLAYS CALORIES BURNED AT 3.9 Cal/min CONSTANT.
* ____________________________________________________________
* This program computes and displays calories burned on a
* treadmill at a constant rate of 3.9 calories per minute. After
* the user enters a non-negative speed, it shows total calories
* burned after 10, 15, 20, 25, and 30 minutes. If a negative
* speed is entered, the user is prompted again until a valid
* value is given.
*
* Computation is based on the formula:
* Calories Burned = Time in Minutes×3.9Calories Burned.
* ____________________________________________________________
* INPUT
* speed
*
*
* OUTPUT
* minutes
* caloriesBurned
*
**************************************************************/
#include <iostream> // For input and output
using namespace std;
int main() {
// --- Step 1: Declare variables ---
double speed; // User's running speed
const double CALORIES_PER_MINUTE = 3.9; // Fixed rate
int times[] = {10, 15, 20, 25, 30}; // Times to calculate
int numberOfTimes = 5; // Total time entries
// --- Step 2: Ask for speed ---
cout << "Enter your running speed: ";
cin >> speed;
// --- Step 3: Input validation ---
while (speed < 0) {
cout << "Speed must be zero or positive. Please enter again: ";
cin >> speed;
}
// --- Step 4: Loop through the time values ---
for (int i = 0; i < numberOfTimes; i++) {
int minutes = times[i]; // Current time from the list
double caloriesBurned = minutes * CALORIES_PER_MINUTE;
cout << "After " << minutes << " minutes: "
<< caloriesBurned << " calories burned." << endl;
}
// --- Step 5: End the program ---
return 0;
}