-
More complex Function
Ok, My question for this one is a bit more complicated. What I am trying to do is to get the program to first calculate the Basal Metabolic Rate, then the amount of calories needed to maintain the current weight, and lastly convert it. It compiles, but I believe I established my functions wrong because they do not seem to calculate properly. Any suggestions?
Code:
#include <iostream>#include <cmath>
using namespace std;
float metabolic_rate;
// Returns the metabolic_rate as a floating point value.
float digestion_energy;
// Returns the digestion_energy as a floating point value.
int main ()
{
int P, intensity, minutes, calories, servings;
double weight = P;
double metabolic_rate = 70 * pow ( P / 2.2 , 0.756 );
double activity = 0.0385 * intensity * P * minutes;
double digestion_energy = calories * .01;
{
cout << "Welcome to the Basal Metabolic Rate program.";
cout << endl;
cout << "First we need your weight. Please enter your weight: ";
cin >> weight;
cout << endl;
cout << "Please enter the intensity of your workout: ";
cin >> intensity;
cout << endl;
cout << "Please enter the duration (in minutes) that you worked out: ";
cin >> minutes;
cout << endl;
cout << "Please enter the calories you consumed: ";
cin >> calories;
cout << endl;
{
cout << "We will first find the ammount of calories to start your Basal Metabolic Rate." <<endl;
cout << "Your Basal Metabolic Rate is: ";
cout << metabolic_rate << endl;
cout << endl;
}
{
cout << "Next we will calculate the calories required for your activity." << endl;
cout << "The total ammoount of calories you need is: ";
cout << digestion_energy;
cout << endl;
}
{
cout << "Lastly we will convert the calories you need into servings.";
cout << "You must have a total of: ";
cout << servings;
cout << " in order to maintain your current weight.";
}
}
return 0;
}
-
Well to start you do not have any function at all except main() which is mandatory.
Then, you use P while it has not been assigned any value and the same goes for intensity and minutes and calories. You cannot make calculations with empty variables.
You also have two include directives on one line. I'm not such if the linker will understand it but you should not do it anyway. One instruction - one line.
And finally... why the curly braces ? You have them all over the place for no reason. You only need curly braces when entering a new logical segment of your code (inside of a function, inside of a class, inside of if/else/while/for statement, etc.)
-
Ok, this is my new code. Any suggestions?
Code:
#include <iostream>#include <cmath>
using namespace std;
double basal_rate ( int weight_par, int calories );
double physical_activity( int intensity_par, int minutes_par, int calories_par );
int main ()
{
int P;
double intensity, minutes, calories;
{
cout << "Welcome to the Basal Metabolic Rate program.";
cout << endl;
cout << "First we need your weight. Please enter your weight: ";
cin >> P;
cout << endl;
cout << "Please enter the intensity of your workout: ";
cin >> intensity;
cout << endl;
cout << "Please enter the duration (in minutes) that you worked out: ";
cin >> minutes;
cout << endl;
cout << "Please enter the calories you consumed: ";
cin >> calories;
cout << endl;
double physical_activity = 0.0385 * intensity * P * minutes;
double digestion_energy = calories * .01;
double basal_rate = 70 * pow ( P / 2.2 , 0.756);
cout << "We will first find the ammount of calories to start your Basal Metabolic Rate." << endl;
cout << "Your Basal Metabolic Rate is: ";
cout << basal_rate;
cout << endl;
cout << "Next we will calculate the calories required for your activity." << endl;
cout << "The total ammoount of calories you need is: ";
cout << physical_activity;
cout << endl;
int serving_size = 1 + calories;
cout << "The serving size you need to consume daily is ";
cout << serving_size;
cout << " in order to maintain your current weight." << endl;
}
return 0;
}
double basal_rate ( int weight_par, int calories_par )
{
return ( calories_par, weight_par);
}
double physical_activity( int intensity_par, int minutes_par, int calories_par )
{
return ( intensity_par, minutes_par, calories_par );
}
-
You have some serious knowledge deficiencies. Read through our C++ Made Easy Tutorials, specifically pay attention to the lesson on functions. Think about your homework, and then come up with a solution. It appears we are all just wasting our time with you.
BTW, posting BS code and asking for help is like posting no code at all. You have clearly not paid any attention to the advice that has already been given. Stop wasting our time with this until you are willing to learn.
-
-
>>#include <iostream>#include <cmath>
Still wrong.
>>return ( intensity_par, minutes_par, calories_par );
Will not do what you want. What do you want it to do?