void functions

hello! for an assignment we have to use void and value returning functions.
we have to calculate the metabolic power of an animal. here is my program:

#include <iostream>
using namespace std;

void GetData(double &, double &, double &, double &, double &, double &);
double CalcVoc (double, double, double);
double CalcSTP (double, double, double);
double CalcMP (double, double);
void PrintMetPow (double, double, double, double, double, double, double);

int main ()
{
double mass;
double aT;
double cP;
double pre;
double post;
double vaf;
double stp;
double mp;
double voc;

GetData (mass, aT, cP, pre, post, vaf);

voc = CalcVoc (vaf, pre, post);

stp = CalcSTP (voc, vaf, aT);

mp = CalcMP (stp, mass);

PrintMetPow (mass, aT, cP, pre, post, vaf, mp);

return 0;
}

void GetData (double & mass, double & at, double & cP, double & pre, double & post, double & vaf)
{
cout << "Please input the mass of the animal: ";
cin >> mass;
cout << "Please input the ambient temperature: ";
cin >> at;
cout << "Please input the chamber pressure: ";
cin >> cP;
cout << "Please input concentration of oxygen in ambient air (pre-animal): ";
cin >> pre;
cout << "Please input concentration of oxygen in ambient air (post-animal): ";
cin >> post;
cout << "Please input the rate of oxygen: ";
cin >> vaf;
}

//This is suppose to be a void function but i dont understand how that will work?
double CalcVoc (double vaf, double pre, double post)
{
double voc = vaf * (pre - post) / (1 - post);
return voc;
}

double CalcSTP (double voc, double cp, double at)
{
double stp = voc * (cp / 760) * (273 / (273 + at));
return stp;
}

double CalcMP (double stp, double mass)
{
double mp = stp / (mass * 0.179);
return mp;
}

void PrintMetPow (double mass, double at, double cp, double pre, double post, double vaf, double mp)
{
cout << "The mass of this animal is " << mass << " grams" << endl;
cout << "The ambient temperature is " << at << " degrees" << endl;
cout << "The chamber pressure is " << cp << " mmHG" << endl;
cout << "The concentration of ambient air (pre-animal) is: " << pre << endl;
cout << "The concentration of ambient air (post-animal) is: " << post << endl;
cout << "The rate of oxygen is: " << vaf << endl;
cout << "The metabolic power for this mammal or reptile is: " << mp << endl;
}


for CalcVoc it is suppose to be a void function. I used a value returning function, i dont understand how you would get the numbers for voc using a void function? thanks in advance!!
The same as for getData, you send the value you want assigned as a reference
oohhhh thank you so much!
i have another question

Step 3. Correct voc to standard temperature and pressure (stp).
stp = voc * (cp / 760) * (c1 / (c1 + at)),

where c1 is the constant value 273 for correcting from voc to stp.

Step 4. Calculate metabolic power (mp) from stp.
mp = stp / (mass * c2),

where c2 is the constant value 0.179 for calculating mp from stp.


those are the formulas we are suppose to use.. i didnt understand what c1 and c2 is so i just put 273 in for c1 and 0.179 for c2

double CalcSTP (double voc, double cp, double at)
{
double stp = voc * (cp / 760) * (273 / (273 + at));
return stp;
}

double CalcMP (double stp, double mass)
{
double mp = stp / (mass * 0.179);
return mp;
}


i dont think this is correct but i dont know what else to do. Any ideas?
Not quite sure what you are wanting, if you just want to use c1 and c2 instead of 273 and 0.179 then you could use.

#define c1 273
#define c2 0.179

or

const int c1 = 273
const float c2 = 0.179
(Avoid defines btw)
hmm hmm hmm.. ya well if i do that it doesnt give me the right answer, but its okay thanks anyways ill just ask the teacher :)
Topic archived. No new replies allowed.