hi this is my first post and i have a problem with classes
i have made a small health meter
however the choices are not independent
for example if i select choice one and enter the values it works fine
but if i now select choice two it uses the same values of choice one
and just gives an output without letting me enter the values
Here is the source code
Code:
#include <cstdlib>
#include <iostream>
using namespace std;
////////////////
class BodyStats
{
public:
BodyStats();
//~BodyStats();
int HeartRate,Age,Height,Bodyweight;
double Bweight,LitersWater,MinWater,RMR;
void FindHeartRate();
void FindMenRMR();
void FindFemaleRMR();
void FindMinimumWater();
void Stats();
void Choice();
/*void FindEnergyExpenditure()
{
cout<<"Enter your RMR"<<endl;
cin<<RMR;
cout<<
}*/
};
BodyStats::BodyStats()
: HeartRate(0),
Age(0),
Height(0),
Bodyweight(0)
{}
void BodyStats::FindHeartRate()
{
while(Age<=0)
{
cout<<"Enter your age";
cin>>Age;
if(Age<=0)
cout<<"Please Enter a valid age"<<endl;
}
HeartRate = 220-Age;
cout<<"your optimal heart rate is"<<HeartRate;
}
void BodyStats::FindMenRMR()
{
while(Bodyweight<=0)
{
cout<<"Enter your Weight(KG)";
cin>>Bodyweight;
if(Bodyweight<=0)
cout<<"Please Enter a valid weight"<<endl;
cout<<""<<endl;
}
while(Height <= 0)
{
cout<<"Enter your Height(CM)";
cin>>Height;
if(Height <= 0)
cout<<"Please Enter a valid height"<<endl;
cout<<""<<endl;
}
while(Age <= 0)
{
cout<<"Enter your age";
cin>>Age;
if(Age <= 0)
cout<<"Please Enter a valid age"<<endl;
cout<<""<<endl;
}
RMR = 66 + (13.7 * Bodyweight)+(5 * Height)-(6.8 * Age);
cout<<"Your RMR is = "<<RMR<<endl;
}
void BodyStats::FindFemaleRMR()
{
while(Bodyweight<= 0)
{
cout<<"Enter your Weight(KG)"<<endl;
cin>>Bodyweight;
if(Bodyweight <= 0 || Bodyweight>=200)
cout<<"Enter a valid weight"<<endl;
}
while(Height<= 0 || Height >= 250 )
{
cout<<"Enter your Height(CM)"<<""<<endl;
cin>>Height;
if (Height<= 0 || Height >= 250)
cout<<"Enter a valid height"<<endl;
}
while(Age<=5 || Age>=100)
{
cout<<"Enter your age"<<""<<endl;
cin>>Age;
if (Age<=5 || Age>=100)
cout<<"Enter a valid age"<<endl;
}
RMR = 655 + (9.6 * Bodyweight)+(1.8 * Height)-(4.7 * Age);
cout<<" "<<endl;
cout<<"Your RMR is" <<""<<RMR<<endl;
cout<<" "<<endl;
}
void BodyStats::FindMinimumWater()
{
cout<<"Enter Bodyweight"<<endl;
cin>>Bodyweight;
Bweight = Bodyweight * 2.2;
MinWater = Bweight / 2;
LitersWater = MinWater/35;
cout<<"Your optimal water intake should be"<<LitersWater<<"liters"<<endl;
}
void BodyStats::Stats()
{
cout<<"Calories Per Gram"<<endl;
cout<<"1 gram fat = 8 calories"<<endl;
cout<<"1 gram carbohydrate = 4 calories"<<endl;
cout<<"1 gram protein = 4 calories"<<endl;
}
int main(int argc, char *argv[])
{
BodyStats Body;
int choice;
while(choice!=6)
{
cout<<"1)Men RMR"<<endl;
cout<<"2)Women RMR"<<endl;
cout<<"3)Find Optimal Heart Rate"<<endl;
cout<<"4)Minimum Water"<<endl;
cout<<"5)Energy Expenditure"<<endl;
cout<<"6)Quit"<<endl;
cout<<"Enter your choice"<<endl;
cin>>choice;
switch(choice)
{
case 1:
Body.FindMenRMR();
break;
case 2:
Body.FindFemaleRMR();
break;
case 3:
Body.FindHeartRate();
break;
case 4:
Body.FindMinimumWater();
break;
case 5:
Body.Stats();
break;
case 6:
return 0;
break;
}
}
system("PAUSE");
return 0;
}
please help out.
Thanks