Classes Error C++

im having issues with my code and since im just starting my C++ course im still having problems with classes, I have the following code and im trying to get a user to enter the name, type and age of a pet but i cant get the program to display the information given , can you look at my code and point out that my issue is, thanks

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include "iostream"
#include "string"
using namespace std;

class Pet
{
public:								
	Pet();						
	Pet(string name, string type, int age);	
	string getName() const;
	string getType() const;
	int getAge() const;

private:
	string name;
	string type;
	int age;
};

Pet::Pet(std::string pname, string ptype, int page)
{
	name = pname;
	type = ptype;
	age = page;
}

string Pet::getName() const
{
	return name;
}

string Pet::getType() const
{
	return type;
}

int Pet::getAge() const
{
	return age;
}



int main()
{
	string name;
	string type;
	int age;
	cout << "Please enter the name of your pet: \n";
	cin >> name;
	cout << "Please enter what type of animal is your pet: \n";
	cin >> type;
	cout << "Please enter the age of your pet: \n";
	cin >> age;

	cout << endl << endl;
	cout << "Name: \t" << pname << endl;
	cout << "Type: \t" << ptype << endl;
	cout << "age: \t" << page << endl;
	
	return 0;
}
Your code does not even compile due to:
 In function 'int main()':
57:24: error: 'pname' was not declared in this scope
58:24: error: 'ptype' was not declared in this scope
59:23: error: 'page' was not declared in this scope 


Your program does not have any Pet objects. You have to change your main().
i rewrote my code making it more simpler adding this:
1
2
3
4
5
6
7
8
9
obj.set_name(newName);
	cout << " " << obj.get_name();
	cout << endl;
	obj.set_type(newType);
	cout << " " << obj.get_type();
	cout << endl;
	obj.set_age(newAge);
	cout << " " << obj.get_age();
	cout << endl;


also changing my class code.

Thanks for pointing that out, i was stress out, that was why i didnt see it crearly :D
Why don't you use the Pet::Pet(string, string, int)?
Topic archived. No new replies allowed.