hi Can you help my project?

Hi:D I'm beginner at C++ program.
I have some problem.
I'll make a project that calorie caculator, but there is some problem at my code.

My code is

#include<iostream>
#include<cstring>

using namespace std;
const int NAME_LEN=20;

enum{MAKE=1, DEPOSIT, EXERCISE, EXIT};
enum{O2EXERCISE, NOO2EXERCISE, OUT};
enum{WALK, RUN, GO};
enum{UPDOWN, PUSHUP, SQUAT,SIDE};

class User
{
private:
int exerID;
char *cusName;
int sex;
int height;
int weight;
double calory;

public:
User(int ID, int usersex, char *name, int hei, int wei, double kcal);
User(User &ref);
int GetexerID() const;
void ShowAccInfo() const;
void GetKcal(double kcal);
~User();
};

User::User(int ID, int usersex, char *name, int hei, int wei, double kcal)
:exerID(ID), sex(usersex), height(hei), weight(wei), calory(kcal)
{
cusName=new char[strlen(name)+1];
strcpy(cusName,name);
}

User::User(User &ref)
: exerID(ref.exerID), sex(ref.sex), height(ref.height), weight(ref.weight), calory(ref.calory)
{
cusName=new char[strlen(ref.cusName)+1];
strcpy(cusName, ref.cusName);
}

int User::GetexerID() const
{
return exerID;
}

void User::GetKcal(double kcal)
{
calory+=kcal;
}

void User::ShowAccInfo() const
{
double bmi;
bmi = weight/((height*0.01)*(height*0.01));

cout<<"ID:"<<exerID<<endl;
cout<<"name: "<<cusName<<endl;
cout<<"BMI: "<<bmi<<endl;
if(bmi<19)
cout<<"low"<<endl;
if(bmi>19 && bmi<25)
cout<<"normal"<<endl;
if(bmi>=25 && bmi<=30)
cout<<"high"<<endl;
if(bmi>30)
cout<<"fat"<<endl;
cout<<"total calorie: "<<calory<<endl;
}

User::~User()
{
delete []cusName;
}

class Sports
{
protected:
User *accArr[100]; //User 저장을 위한 배열
int accNum; //저장된 User수
public:
Sports() : accNum(0)
{}
void ShowMenu(void) const;
void MakeUser(void);
void ChoiceUser();
void ShowAllUserInfo(void) const;
void ShowKcalInfo(double kcal, int id);
~Sports();

};

void Sports::ShowMenu(void) const
{
cout<<"------MENU------"<<endl;
cout<<"1. user register"<<endl;
cout<<"2. exercise"<<endl;
cout<<"3. show all info"<<endl;
cout<<"4. exit"<<endl;
}

void Sports::MakeUser(void)
{
int id;
char name[NAME_LEN];
int sex;
int height;
int weight;
double kcal = 0;

cout<<"[user register]:"<<endl;
cout<<"ID:"; cin>>id;
cout<<"name :"; cin>>name;
cout<<"sex(m:1, f:2) :"; cin>>sex;
cout<<"high:"; cin>>height;
cout<<"weight :"; cin>>weight;
cout<<endl;

accArr[accNum++]=new User(id, sex, name, height, weight, kcal);
}

class O2Sports : public Sports
{
public:
void oxiexercise(void);
};

class ExeWalk : public O2Sports
{
public:
void Walk(void)
{
Sports spr;
int id;
int time;
double kcal;

cout<<"[walk]"<<endl;
cout<<"ID : ";cin>>id;
cout<<"how long?";cin>>time;
kcal = time*30;

spr.ShowKcalInfo(kcal, id);




}

};

void Sports::ShowKcalInfo(double kcal, int id)
{
for(int i=0; i<accNum; i++)
{
if(accArr[i]->GetexerID()==id)
{
accArr[i]->GetKcal(kcal);
cout<<"calorie complite!"<<endl<<endl;
cout<<"total calorie: "<<kcal<<"."<<endl;
return;
}
}
cout<<"no register ID"<<endl;
}

class ExeRun : public O2Sports
{
public:
void Run(void)
{
int time;
double kcal;


cout<<"[run]"<<endl;
cout<<"how long?";cin>>time;
kcal = time*50;
cout<<"total calorie :"<<kcal<<"."<<endl;


}
};

void O2Sports::oxiexercise(void)
{
ExeWalk ew;
ExeRun er;
int choice;

cout<<"[o2 exercise]"<<endl;
cout<<"1. walk"<<endl;
cout<<"2. run"<<endl;
cout<<"3. exit"<<endl;
cout<<"choice:";cin>>choice;cout<<endl;

switch(choice-1)
{
case WALK:
ew.Walk();
break;
case RUN:
er.Run();
break;
case GO:
return;
default:
cout<<"re choice"<<endl;
}
}


class NoO2Sports : public Sports
{
public:
void nooxexercise(void);
};

class ExeUpDown : public NoO2Sports
{
public:
void Updown(void)
{
int time;
double kcal;

cout<<"[updown]"<<endl;
cout<<"how many?";cin>>time;
kcal = time*30;
cout<<"total calorie "<<kcal<<"."<<endl;

}


};

class ExePushUp : public NoO2Sports
{
public:
void PushUp(void)
{
int time;
double kcal;

cout<<"[push up]"<<endl;
cout<<"how many?";cin>>time;
kcal = time*30;
cout<<"total calorie:"<<kcal<<"."<<endl;


}
};

class ExeSquat : public NoO2Sports
{
public:
void Squat(void)
{
int time;
double kcal;

cout<<"[squat]"<<endl;
cout<<"how many?";cin>>time;
kcal = time*30;
cout<<"total calorie:"<<kcal<<"."<<endl;



}
};


void NoO2Sports::nooxexercise(void)
{
ExeUpDown eu;
ExePushUp ep;
ExeSquat es;
int choice;

cout<<"[no o2 exercise]"<<endl;
cout<<"1. up down"<<endl;
cout<<"2. pushup"<<endl;
cout<<"3. squat"<<endl;
cout<<"4. exit"<<endl;
cout<<"choice:";cin>>choice;cout<<endl;

switch(choice-1)
{
case UPDOWN:
eu.Updown();
break;
case PUSHUP:
ep.PushUp();
break;
case SQUAT:
es.Squat();
break;
case SIDE:
return;
default:
cout<<"re choice"<<endl;
}
}


void Sports::ChoiceUser(void)
{
int choice;
O2Sports o2;
NoO2Sports no2;


cout<<"[exercise]"<<endl;
cout<<"1. o2 exercise:"<<endl;
cout<<"2. no o2 exercise:"<<endl;
cout<<"3. exit"<<endl;
cout<<"choice:";cin>>choice;cout<<endl;

switch(choice-1)
{
case O2EXERCISE:
o2.oxiexercise();
break;
case NOO2EXERCISE:
no2.nooxexercise();
break;
case OUT:
return;
default:
cout<<"re choice"<<endl;
}


}


void Sports::ShowAllUserInfo(void) const
{
for(int i=0; i<accNum; i++)
{
accArr[i]->ShowAccInfo();
cout<<endl;
}
}



Sports::~Sports()
{
for(int i=0; i<accNum; i++)
delete accArr[i];
}

int main(void)
{
Sports spr;
int choice;

while(1)
{
spr.ShowMenu();
cout<<"choice:";
cin>>choice;
cout<<endl;

switch(choice)
{
case MAKE:
spr.MakeUser();
break;
case DEPOSIT:
spr.ChoiceUser();
break;
case EXERCISE:
spr.ShowAllUserInfo();
break;
case EXIT:
return 0;
default:
cout<<"re choice"<<endl;
}
}


return 0;
}


Debugging is well, but I think this part :

void Sports::ShowKcalInfo(double kcal, int id)
{
for(int i=0; i<accNum; i++)
{
if(accArr[i]->GetexerID()==id)
{
accArr[i]->GetKcal(kcal);
cout<<"calorie complite!"<<endl<<endl;
cout<<"total calorie: "<<kcal<<"."<<endl;
return;
}
}
cout<<"no register ID"<<endl;
}

but result page always show "no register ID".
help me...
-Lots of c-style stuff, you might wanna read a good c to c++ tutorial / migration guide(the "(void)" & c-strings are the big ones).
-Almost no comments at all...
-You should use a vector to store the clients.

You also have a really weird structure that is hard to read, weird names(why does "EXCERCISE" show user info?), and excessive use of classes and functions.

Overall just made one class, and make the functions that you need in it( make the functions inside the class, because then people don't need to hunt for the function ).
Topic archived. No new replies allowed.