Jump to content

C++:Help need with a game

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
7 replies to this topic

#1
Ratchet2246

Ratchet2246

    Newbie

  • Members
  • PipPip
  • 12 posts
#include<iostream>

using namespace std;


int random;

int random2;

char wb;

char input;

int i;

int check;

string yn;

string yn2;

class Animal

{ 

public:

    int eat();

    int drink();

    int sleep();

    int findwater();

    void die();

    int stolen();

    int checkdead();

    int checkhunger();

    int checkthirst();

    int checktiredness();

    int checkfood();

    int checkwater();

    int check();

protected:

    int hunger;

    int thirst;

    int tiredness;

    int food;

    int water;

};

int Animal::eat()

{

    if((food==1)&&(hunger<10))

    {

        hunger+=5;

        if(hunger>10)

            hunger=10;

        food=0;

        thirst-=1;

        tiredness-=1;

        return hunger;

    }

    else if((food==1)&&(hunger==10))

    {

        return 11;

    }

    else if(water==0)

    {

        return 12;

    }

}

int Animal::drink()

{

    if((water==1)&&(thirst<10))

    {

        thirst+=5;

        if(thirst>10)

            thirst=10;

        water=0;

        hunger-=1;

        tiredness-=1;

        return thirst;

    }

    else if((water==1)&&(thirst==10))

    {

        return 11;

    }

    else if(water==0)

    {

        return 12;

    }

}

int Animal::stolen()

{

    if(food==1)

    {

        random = rand() % 300 + 1;

        if(random<=100)

        {

            food=0;

            return 1;

        }

        else

        {

            return 0;

        }

    }

    else

    {

        return 0;

    }

}

int Animal::sleep()

{

    if(tiredness<10)

    {

        tiredness+=5;

        if(tiredness>10)

            tiredness=10;

        return tiredness;

    }

    else if(tiredness==10)

    {

        return 11;

    }  

}

int Animal::findwater()

{

    if(water==0)

    {

        random = rand() % 300 + 1;

        if(random<=200)

        {

            water=1;

            hunger-=1;

            thirst-=1;

            tiredness-=2;

            return 1;

        }

        else if((random>200)&&(random<=300))

        {

            thirst-=1;

            hunger-=1;

            tiredness-=2;

            return 0;

        }

        water=1;

        hunger-=1;

        thirst-=1;

        tiredness-=2;

    }

    else

    {

        return 11;

    }

}

void Animal::die()

{

    cout<<"Uh-oh; you're dead!\n";

    cin.get();

    exit(0);

}

int Animal::checkdead()

{

    if((hunger<=0)||(thirst<=0)||(tiredness<=0))

        return 1;

    else

        return 0;

}

int Animal::checkhunger()

{

    return hunger;

}

int Animal::checkthirst()

{

    return thirst;

}

int Animal::checktiredness()

{

    return tiredness;

}

int Animal::checkfood()

{

    return food;

}

int Animal::checkwater()

{

    return water;

}

int Animal::check()

{

    tiredness-=1;

}

class Bear : public Animal

{

public:

    Bear();

    ~Bear();

    int seek();

};

Bear::Bear()

{

    hunger=10;

    thirst=10;

    tiredness=10;

    food=0;

    water=0;

}

Bear::~Bear()

{

}

int Bear::seek()

{

    if(food==0)

    {

        random = rand() % 300 + 1;

        if(random<=100)

        {

            food=1;

            thirst-=1;

            hunger-=1;

            tiredness-=2;

            return 1;

        }

        else if((random>100)&&(random<=200))

        {

            food=1;

            thirst-=1;

            hunger-=1;

            tiredness-=2;

            return 2;

        }

        else if((random>200)&&(random<=300))

        {

            thirst-=1;

            hunger-=1;

            tiredness-=2;

            return 0;

        }

    }

    else if(food==1)

    {

         return 11;        

    }

}

class Wolf : public Animal

{

public:

    Wolf();

    ~Wolf();

    int hunt();

};

Wolf::Wolf()

{

    hunger=10;

    thirst=10;

    tiredness=10;

    food=0;

    water=0;

}

Wolf::~Wolf()

{

}

int Wolf::hunt()

{

    if(food==0)

    {

        random = rand() % 300 + 1;

        if(random<=100)

        {

            food=1;

            thirst-=1;

            hunger-=1;

            tiredness-=2;

            return 1;

        }

        else if((random>100)&&(random<=200))

        {

            food=1;

            thirst-=1;

            hunger-=1;

            tiredness-=2;

            return 2;

        }

        else if((random>200)&&(random<=300))

        {

            thirst-=1;

            hunger-=1;

            tiredness-=2;

            random2 = rand() % 300 + 1;

            if(random2<=100)

                return 3;

            else if((random2>100)&&(random2<=200))

                return 4;

            else if((random2>200)&&(random2<=300))

                return 5;

        }

    }

    else if(food==1)

    {

         return 11;        

    }

}

Bear user;

void e()

{

    check=user.eat();

    if(check<=10)

    {

        cout<<"You ate the food you were carrying.\n";

        cout<<"You're hunger level is now at "<<check<<".\n\n";

    }

    else if(check==11)

    {

        cout<<"But you're not hungry!\n\n";

    }

    else if(check==12)

    {

        cout<<"But you don't have any food to eat!\n\n";

    }

}

void d()

{

    check=user.drink();

    if(check<=10)

    {

        cout<<"You drunk out of the water you were near.\n";

        cout<<"You're thirst level is now at "<<check<<".\n\n";

    }

    else if(check==11)

    {

        cout<<"But you're not thirsty!\n\n";

    }

    else if(check==12)

    {

        cout<<"But you're not near any water to drink!\n\n";

    }

}

void s()

{

    check=user.sleep();

    if(check<=10)

    {

        cout<<"You lay down and took a nap.\n";

        cout<<"You're tiredness level is now at "<<check<<".\n\n";

        check=user.stolen();

    if(check==1)

         cout<<"As you get up, you realise that someone has stolen the food you were carrying!\n\n";                        

    }

    else if(check==11)

    {

         cout<<"But you're not tired!\n\n";

    }

}

void f()

{

    check=user.findwater();

    if(check==1)

    {

        cout<<"You found water! It took a lot of effort though!\n\n";

    }

    else if(check==0)

    {

        cout<<"Unfourtunatley, after all the effort you put in, you still didn't find any water!\n\n";

    }

    else if(check==11)

    {

        cout<<"But you're all ready at water!\n\n";

    }

}

void c()

{

    if(user.checkfood()==1)

        yn="yes";

    else

        yn="no";

    if(user.checkwater()==1)

        yn2="yes";

    else

        yn2="no";

    cout<<"Hunger: "<<user.checkhunger()<<".\n";

    cout<<"Thirst: "<<user.checkthirst()<<".\n";

    cout<<"Tiredness: "<<user.checktiredness()<<".\n";

    cout<<"Near Water: "<<yn2<<".\n";

    cout<<"Carrying Food: "<<yn<<".\n\n";

    user.check();

    cout<<"That took some effort telling yourself your stats!\n\n";

}


int main(void)

{

    user.~Bear();

    cout<<"Do you want to be a wolf (w) or a bear (b)? ";

    cin>>wb;

    cin.ignore();

    if(wb=='b')

    {

        Bear user;

        cout<<"You are a bear living in the deep dark forests of Ramsainia.\nYou are the greatest and strongest bear in the forest so no-one dare challenge you but still, the life of a bear is hard, and merely surviving is a challenge in itself...\n\n";

        cout<<"The controls: e - eat any food you are carrying\n              d - drink any water that is near you\n              s - sleep\n              f - find water\n              g - gather food\n              c - check current statistics\n              x - end the program\n\n";

        cout<<"The statistics: hunger\n                thirst\n                tiredness\n                near water\n                carrying food\n\n";

        cout<<"The rules: You must eat to replenish hunger, drink to replenish thirst and sleep to replenish tiredness.\n           You must have food to eat and you must be near water to drink.\n           You're hunger thirst and tiredness fall gradually every turn you take, also if you do something that involves moving, you're sleep falls by extra.\n           If you're hunger, thirst or sleep falls to zero, you die.\n\n";

        for(i=10;i>5;i++)

        {

            if(user.checkdead()==0)

            {

                cout<<"What do you want to do? ";

                cin>>input;

                cin.ignore();

                if(input=='e')

                {

                    e();

                }

                else if(input=='d')

                {

                    d();

                }

                else if(input=='s')

                {

                    s();

                }

                else if(input=='f')

                {

                    f();

                }

                else if(input=='g')

                {

                    check=user.seek();

                    if(check==1)

                    {

                        cout<<"You found some berries! It took a lot of effort though!\n\n";

                    }

                    else if(check==2)

                    {

                        cout<<"You found some honey! It took a lot of effort though!\n\n";

                    }

                    else if(check==0)

                    {

                        cout<<"Unfourtunatley, after all the effort you put in, you still didn't find any food!\n\n";

                    }

                    else if(check==11)

                    {

                        cout<<"You can only carry one thing at a time!\n\n";

                    }

                }

                else if(input=='c')

                {

                     c();

                }

                else if(input=='x')

                {

                    cout<<"Thanks for playing!\n";

                    break;

                }

                else

                {

                    cout<<"\nError - you did not input a valid command!\n\n";

                }

            }

            else if(user.checkdead()==1)

            {

                user.die();

            }

        }

    }

    if(wb=='w')

    {

        Wolf user;

        cout<<"You are a wolf living in the deep dark forests of Ramsainia.\nYou are the greatest and strongest wolf in the forest so no-one dare challenge you but still, the life of a wolf is hard, and merely surviving is a challenge in itself...\n\n";

        cout<<"The controls: e - eat any food you are carrying\n              d - drink any water that is near you\n              s - sleep\n              f - find water\n              h - hunt for food\n              c - check current statistics\n              x - end the program\n\n";

        cout<<"The statistics: hunger\n                thirst\n                tiredness\n                near water\n                carrying food\n\n";

        cout<<"The rules: You must eat to replenish hunger, drink to replenish thirst and sleep to replenish tiredness.\n           You must have food to eat and you must be near water to drink.\n           You're hunger thirst and tiredness fall gradually every turn you take, also if you do something that involves moving, you're sleep falls by extra.\n           If you're hunger, thirst or sleep falls to zero, you die.\n\n";

        for(i=10;i>5;i++)

        {

            if(user.checkdead()==0)

            {

                cout<<"What do you want to do? ";

                cin>>input;

                cin.ignore();

                if(input=='e')

                {

                    e();

                }

                else if(input=='d')

                {

                    d();

                }

                else if(input=='s')

                {

                    s();

                }

                else if(input=='f')

                {

                    f();

                }

                else if(input=='h')

                {

                    check=user.hunt();

                    if(check==1)

                    {

                        cout<<"You found and killed a deer! It took a lot of effort though!\n\n";

                    }

                    else if(check==2)

                    {

                        cout<<"You found and killed a wild boar! It took a lot of effort though!\n\n";

                    }

                    else if(check==3)

                    {

                        cout<<"Unfourtunatley, after all the effort you put in, you still didn't find any food!\n\n";

                    }

                    else if(check==4)

                    {

                        cout<<"Unfourtunatley, you found a deer but it got away! That chase was tiring though!\n\n";

                    }

                    else if(check==5)

                    {

                        cout<<"Unfourtunatley, you found a wild boar but you couldn't kill it! That fight was tiring though!\n\n";

                    }

                    else if(check==11)

                    {

                        cout<<"You can only carry one thing at a time!\n\n";

                    }

                }

                else if(input=='c')

                {

                    c();

                }

                else if(input=='x')

                {

                    cout<<"Thanks for playing!\n";

                    break;

                }

                else

                {

                    cout<<"\nError - you did not input a valid command!\n\n";

                }

            }

            else if(user.checkdead()==1)

            {

                user.die();

            }

        }

    }

    else

    {

        cout<<"Unidentified Error! Aborting!";

        cin.get();

        return 0;

    }

    cin.get();

    return 0;

}


Everything works fine except when you choose wolf, the hunt function seems to work fine changing food to 1 but when you check stats or try to eat, it acts as if food is still at 0.

Thanks for your help
Ratchet

#2
Ratchet2246

Ratchet2246

    Newbie

  • Members
  • PipPip
  • 12 posts
Just realised I get the same problem with the bear:seek() function. It insists that the user is already carrying food but food definately = 0 and when you try to eat it would suggest the same.

Also why does it show Unidentified Error when you try to quit, it shouldn't because when you quit it breaks the loop and should go straight to the bottom cin.get() return 0.

#3
Ratchet2246

Ratchet2246

    Newbie

  • Members
  • PipPip
  • 12 posts
Okay I fixed the Unidentified Error problem but I still get the main problem.
Here is the new code, I just changed if(wb=='w') to else if(wb=='w'):
#include<iostream>

using namespace std;


int random;

int random2;

char wb;

char input;

int i;

int check;

string yn;

string yn2;

class Animal

{ 

public:

    int eat();

    int drink();

    int sleep();

    int findwater();

    void die();

    int stolen();

    int checkdead();

    int checkhunger();

    int checkthirst();

    int checktiredness();

    int checkfood();

    int checkwater();

    int check();

protected:

    int hunger;

    int thirst;

    int tiredness;

    int food;

    int water;

};

int Animal::eat()

{

    if((food==1)&&(hunger<10))

    {

        hunger+=5;

        if(hunger>10)

            hunger=10;

        food=0;

        thirst-=1;

        tiredness-=1;

        return hunger;

    }

    else if((food==1)&&(hunger==10))

    {

        return 11;

    }

    else if(water==0)

    {

        return 12;

    }

}

int Animal::drink()

{

    if((water==1)&&(thirst<10))

    {

        thirst+=5;

        if(thirst>10)

            thirst=10;

        water=0;

        hunger-=1;

        tiredness-=1;

        return thirst;

    }

    else if((water==1)&&(thirst==10))

    {

        return 11;

    }

    else if(water==0)

    {

        return 12;

    }

}

int Animal::stolen()

{

    if(food==1)

    {

        random = rand() % 300 + 1;

        if(random<=100)

        {

            food=0;

            return 1;

        }

        else

        {

            return 0;

        }

    }

    else

    {

        return 0;

    }

}

int Animal::sleep()

{

    if(tiredness<10)

    {

        tiredness+=5;

        if(tiredness>10)

            tiredness=10;

        return tiredness;

    }

    else if(tiredness==10)

    {

        return 11;

    }  

}

int Animal::findwater()

{

    if(water==0)

    {

        random = rand() % 300 + 1;

        if(random<=200)

        {

            water=1;

            hunger-=1;

            thirst-=1;

            tiredness-=2;

            return 1;

        }

        else if((random>200)&&(random<=300))

        {

            thirst-=1;

            hunger-=1;

            tiredness-=2;

            return 0;

        }

        water=1;

        hunger-=1;

        thirst-=1;

        tiredness-=2;

    }

    else

    {

        return 11;

    }

}

void Animal::die()

{

    cout<<"Uh-oh; you're dead!\n";

    cin.get();

    exit(0);

}

int Animal::checkdead()

{

    if((hunger<=0)||(thirst<=0)||(tiredness<=0))

        return 1;

    else

        return 0;

}

int Animal::checkhunger()

{

    return hunger;

}

int Animal::checkthirst()

{

    return thirst;

}

int Animal::checktiredness()

{

    return tiredness;

}

int Animal::checkfood()

{

    return food;

}

int Animal::checkwater()

{

    return water;

}

int Animal::check()

{

    tiredness-=1;

}

class Bear : public Animal

{

public:

    Bear();

    ~Bear();

    int seek();

};

Bear::Bear()

{

    hunger=10;

    thirst=10;

    tiredness=10;

    food=0;

    water=0;

}

Bear::~Bear()

{

}

int Bear::seek()

{

    if(food==0)

    {

        random = rand() % 300 + 1;

        if(random<=100)

        {

            food=1;

            thirst-=1;

            hunger-=1;

            tiredness-=2;

            return 1;

        }

        else if((random>100)&&(random<=200))

        {

            food=1;

            thirst-=1;

            hunger-=1;

            tiredness-=2;

            return 2;

        }

        else if((random>200)&&(random<=300))

        {

            thirst-=1;

            hunger-=1;

            tiredness-=2;

            return 0;

        }

    }

    else if(food==1)

    {

         return 11;        

    }

}

class Wolf : public Animal

{

public:

    Wolf();

    ~Wolf();

    int hunt();

};

Wolf::Wolf()

{

    hunger=10;

    thirst=10;

    tiredness=10;

    food=0;

    water=0;

}

Wolf::~Wolf()

{

}

int Wolf::hunt()

{

    if(food==0)

    {

        random = rand() % 300 + 1;

        if(random<=100)

        {

            food=1;

            thirst-=1;

            hunger-=1;

            tiredness-=2;

            return 1;

        }

        else if((random>100)&&(random<=200))

        {

            food=1;

            thirst-=1;

            hunger-=1;

            tiredness-=2;

            return 2;

        }

        else if((random>200)&&(random<=300))

        {

            thirst-=1;

            hunger-=1;

            tiredness-=2;

            random2 = rand() % 300 + 1;

            if(random2<=100)

                return 3;

            else if((random2>100)&&(random2<=200))

                return 4;

            else if((random2>200)&&(random2<=300))

                return 5;

        }

    }

    else if(food==1)

    {

         return 11;        

    }

}

Bear user;

void e()

{

    check=user.eat();

    if(check<=10)

    {

        cout<<"You ate the food you were carrying.\n";

        cout<<"You're hunger level is now at "<<check<<".\n\n";

    }

    else if(check==11)

    {

        cout<<"But you're not hungry!\n\n";

    }

    else if(check==12)

    {

        cout<<"But you don't have any food to eat!\n\n";

    }

}

void d()

{

    check=user.drink();

    if(check<=10)

    {

        cout<<"You drunk out of the water you were near.\n";

        cout<<"You're thirst level is now at "<<check<<".\n\n";

    }

    else if(check==11)

    {

        cout<<"But you're not thirsty!\n\n";

    }

    else if(check==12)

    {

        cout<<"But you're not near any water to drink!\n\n";

    }

}

void s()

{

    check=user.sleep();

    if(check<=10)

    {

        cout<<"You lay down and took a nap.\n";

        cout<<"You're tiredness level is now at "<<check<<".\n\n";

        check=user.stolen();

    if(check==1)

         cout<<"As you get up, you realise that someone has stolen the food you were carrying!\n\n";                        

    }

    else if(check==11)

    {

         cout<<"But you're not tired!\n\n";

    }

}

void f()

{

    check=user.findwater();

    if(check==1)

    {

        cout<<"You found water! It took a lot of effort though!\n\n";

    }

    else if(check==0)

    {

        cout<<"Unfourtunatley, after all the effort you put in, you still didn't find any water!\n\n";

    }

    else if(check==11)

    {

        cout<<"But you're all ready at water!\n\n";

    }

}

void c()

{

    if(user.checkfood()==1)

        yn="yes";

    else

        yn="no";

    if(user.checkwater()==1)

        yn2="yes";

    else

        yn2="no";

    cout<<"Hunger: "<<user.checkhunger()<<".\n";

    cout<<"Thirst: "<<user.checkthirst()<<".\n";

    cout<<"Tiredness: "<<user.checktiredness()<<".\n";

    cout<<"Near Water: "<<yn2<<".\n";

    cout<<"Carrying Food: "<<yn<<".\n\n";

    user.check();

    cout<<"That took some effort telling yourself your stats!\n\n";

}


int main(void)

{

    user.~Bear();

    cout<<"Do you want to be a wolf (w) or a bear (b)? ";

    cin>>wb;

    cin.ignore();

    if(wb=='b')

    {

        Bear user;

        cout<<"You are a bear living in the deep dark forests of Ramsainia.\nYou are the greatest and strongest bear in the forest so no-one dare challenge you but still, the life of a bear is hard, and merely surviving is a challenge in itself...\n\n";

        cout<<"The controls: e - eat any food you are carrying\n              d - drink any water that is near you\n              s - sleep\n              f - find water\n              g - gather food\n              c - check current statistics\n              x - end the program\n\n";

        cout<<"The statistics: hunger\n                thirst\n                tiredness\n                near water\n                carrying food\n\n";

        cout<<"The rules: You must eat to replenish hunger, drink to replenish thirst and sleep to replenish tiredness.\n           You must have food to eat and you must be near water to drink.\n           You're hunger thirst and tiredness fall gradually every turn you take, also if you do something that involves moving, you're sleep falls by extra.\n           If you're hunger, thirst or sleep falls to zero, you die.\n\n";

        for(i=10;i>5;i++)

        {

            if(user.checkdead()==0)

            {

                cout<<"What do you want to do? ";

                cin>>input;

                cin.ignore();

                if(input=='e')

                {

                    e();

                }

                else if(input=='d')

                {

                    d();

                }

                else if(input=='s')

                {

                    s();

                }

                else if(input=='f')

                {

                    f();

                }

                else if(input=='g')

                {

                    check=user.seek();

                    if(check==1)

                    {

                        cout<<"You found some berries! It took a lot of effort though!\n\n";

                    }

                    else if(check==2)

                    {

                        cout<<"You found some honey! It took a lot of effort though!\n\n";

                    }

                    else if(check==0)

                    {

                        cout<<"Unfourtunatley, after all the effort you put in, you still didn't find any food!\n\n";

                    }

                    else if(check==11)

                    {

                        cout<<"You can only carry one thing at a time!\n\n";

                    }

                }

                else if(input=='c')

                {

                     c();

                }

                else if(input=='x')

                {

                    cout<<"Thanks for playing!\n";

                    break;

                }

                else

                {

                    cout<<"\nError - you did not input a valid command!\n\n";

                }

            }

            else if(user.checkdead()==1)

            {

                user.die();

            }

        }

    }

    else if(wb=='w')

    {

        Wolf user;

        cout<<"You are a wolf living in the deep dark forests of Ramsainia.\nYou are the greatest and strongest wolf in the forest so no-one dare challenge you but still, the life of a wolf is hard, and merely surviving is a challenge in itself...\n\n";

        cout<<"The controls: e - eat any food you are carrying\n              d - drink any water that is near you\n              s - sleep\n              f - find water\n              h - hunt for food\n              c - check current statistics\n              x - end the program\n\n";

        cout<<"The statistics: hunger\n                thirst\n                tiredness\n                near water\n                carrying food\n\n";

        cout<<"The rules: You must eat to replenish hunger, drink to replenish thirst and sleep to replenish tiredness.\n           You must have food to eat and you must be near water to drink.\n           You're hunger thirst and tiredness fall gradually every turn you take, also if you do something that involves moving, you're sleep falls by extra.\n           If you're hunger, thirst or sleep falls to zero, you die.\n\n";

        for(i=10;i>5;i++)

        {

            if(user.checkdead()==0)

            {

                cout<<"What do you want to do? ";

                cin>>input;

                cin.ignore();

                if(input=='e')

                {

                    e();

                }

                else if(input=='d')

                {

                    d();

                }

                else if(input=='s')

                {

                    s();

                }

                else if(input=='f')

                {

                    f();

                }

                else if(input=='h')

                {

                    check=user.hunt();

                    if(check==1)

                    {

                        cout<<"You found and killed a deer! It took a lot of effort though!\n\n";

                    }

                    else if(check==2)

                    {

                        cout<<"You found and killed a wild boar! It took a lot of effort though!\n\n";

                    }

                    else if(check==3)

                    {

                        cout<<"Unfourtunatley, after all the effort you put in, you still didn't find any food!\n\n";

                    }

                    else if(check==4)

                    {

                        cout<<"Unfourtunatley, you found a deer but it got away! That chase was tiring though!\n\n";

                    }

                    else if(check==5)

                    {

                        cout<<"Unfourtunatley, you found a wild boar but you couldn't kill it! That fight was tiring though!\n\n";

                    }

                    else if(check==11)

                    {

                        cout<<"You can only carry one thing at a time!\n\n";

                    }

                }

                else if(input=='c')

                {

                    c();

                }

                else if(input=='x')

                {

                    cout<<"Thanks for playing!\n";

                    break;

                }

                else

                {

                    cout<<"\nError - you did not input a valid command!\n\n";

                }

            }

            else if(user.checkdead()==1)

            {

                user.die();

            }

        }

    }

    else

    {

        cout<<"Unidentified Error! Aborting!";

        cin.get();

        return 0;

    }

    cin.get();

    return 0;

}



#4
Ratchet2246

Ratchet2246

    Newbie

  • Members
  • PipPip
  • 12 posts
Okay; yet another problem.
I just found out that when hunger reaches 0 you don't die like you should.
Any ideas?

#5
marwex89

marwex89

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 10,720 posts
Hehe.. 3 posts in 20 minutes, all replaying to yourself... Then I suggest you go debugging. Maybe you'll learn something and really feel happy that you accomplished something. Sorry for not actually helping you out (other than a little bump), maybe I will look at it later. :D
Hey! Check out my new Toyota keyboaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

#6
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,720 posts
Print out stuff to the console to trace what's going on, i.e. use cout to print out the values of variables or notification strings like "Entering Function XXX with arguments A=6, B=5" and so on.

#7
telboon

telboon

    Newbie

  • Members
  • PipPip
  • 26 posts
For the few functions(e,d,s,f) they used the "Bear user"(global variable) for all their operations. I don't actually think you are using it right. The user they are editing are not the user for your animal. So, the stats the functions show are for the global variable user, instead for the one used in main function.

I'll suggest that you use void e(Animal &user) instead, for all e,d,s,f, and eliminate the use of the global variable user. This way, it'll make sure all the functions are using the user you intended.

Well, at least this worked for me when I tried to edit your code. Hopefully it'll work for you as well:)

However, I'm not sure why the functions are not reporting errors, when they are assessing a destroyed class. Hopefully some enlighten ones will explain this...;)

#8
telboon

telboon

    Newbie

  • Members
  • PipPip
  • 26 posts
Hey wait, I got it.

That user.~Bear() did not destroy the class. So, whenever you go back to those function, they access the still-existing global user.