Why is this happening?

Posts 1–7 of 7 · Page 1 of 1
Why is this happening?
Ok. Whenever I run the program it displays
Leo is a dog who is -856993460 and weighs -858993460 pounds. Wtf /

[PHP]#include <general.h>

class Dog
{
public:
int GetAge();
void SetAge(int age);

int GetWeight();
void SetWeight(int weight);

void Bark();
private:
int itsAge;
int itsWeight;
string itsName;
};

int Dog::GetAge()
{
return itsAge;
}

int Dog::GetWeight()
{
return itsWeight;
}



void Dog::SetAge(int age)
{
age = itsAge;
}

void Dog::SetWeight(int weight)
{
weight = itsAge;
}



void Bark()
{
cout << "Bark\n";
}

int main()
{
//Create Dog
Dog Leo;

//Set Dog age
Leo.SetAge(1);

//Set Dog weight
Leo.SetWeight(6);

cout << "Leo is a dog who is " << Leo.GetAge() << " Years old. And weighs " << Leo.GetWeight() << " Pounds\n";

return 0;
}
[/PHP]
You have your variables backwards.

In your SetAge function and SetWeight function you wrote to the parameter instead of the classes members. Also, you used the itsAge variable for the weight function also...

I love you~
oh.....
Thanks. Will fix

Edit: Now works
Do you have a dog named Leo by any chance?
Quote Originally Posted by Void View Post
Do you have a dog named Leo by any chance?
Yeah. In my book they used an Example with A Cat class, so i changed it to dog
Yeah. Koreans is just my backup acc
Posts 1–7 of 7 · Page 1 of 1

Post a Reply

Similar Threads

Talk with us