What am I doing wrong? Total calories burned calculation

This is my third time ever, writing code... I don't know what I'm doing wrong, but the total calories comes out to zero no matter what values I put in when running the program.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>
#include <iomanip>
using namespace std;

int main()
{

    float weightInPounds, mets, mins, totalCal, calPerMinute;
    const float poundToKilo = 2.2;
    const float formula = 0.075;

    cout << "Hello and Welcome to the Calorie Calculator!\n";
    cout << "Please Enter Your Weight in Pounds: " << endl;
    cin >> weightInPounds;
    cout << "Enter the Number of METs For the Activity: " << endl;
    cin >> mets;
    cout << "Enter the Duration in Minutes: " << endl;
    cin >> mins;
    cout << fixed << setprecision (2);
    totalCal = formula * (weightInPounds / poundToKilo) * mets;
    totalCal = calPerMinute * mins;
    cout << "You burned an estimated " << totalCal << " calories." << endl;

    return 0;
}
calPerMinute is used but is not initialized. I believe you want:
1
2
	calPerMinute = formula * (weightInPounds / poundToKilo) * mets;
	totalCal = calPerMinute * mins;
Last edited on
Thank you SO much Joe!!! Life-saver.
Topic archived. No new replies allowed.