Beginning to learn Object creation

I completely understand that the project that proceeds this is elementary, yet I am failing to understand how to proceed. I want to improve my code so that when the program asks for the humans name, it can differiate between human 1 and human 2. So instead of asking what is the humans weight. It will ask what is sallys weight , if that was what I named it during the humansName function.
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
  #include <iostream>
#include "person.h"
#include <string>

using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

class human{
	public:
		int height;
		int weight;
		string name;
	
			string humanName()
		{
			cout << "What is the humans Name? " <<endl;
			cin >>  name;
			return name;
		}	
		/* How do I get humanHeight and humanWeight to recognize which human they are asking the question for??? Will make program a lot more personal to the user */
		int humanHeight()
		{
			cout << "What is the humans height in inches? " << endl;
			cin >>  height;
			return height;
		}
		int humanWeight()
		{
			cout << "What is the humans weight in pounds?" <<endl;
			cin >>  weight;
			return weight;
		}

		
};


int main() {

	human human1;
	human human2;

	human1.humanName();
	human2.humanName();
		
	human1.humanHeight();
	human2.humanHeight();
 
	
	human1.humanWeight();
	human2.humanWeight();
	

	
	cout << "Hi we are " << human1.name << " and " << human2.name << "." <<endl;
	cout << human1.name << " is " << human1.height << " inches tall." << human2.name << " is " << human2.height << " inches tall." <<endl;
	cout << human1.name << " weighs " << human1.weight << " lbs." << human2.name << " weighs " << human2.weight << " lbs."<<endl;
	
	
	return 0;
}
ok since posting Ive figured I would try to solve my problem and Ive come up with the following. My only question is , is there a way for me to change the question on "What is your humans name?" to a way to recognize it is now asking for the second humans name?

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 "person.h"
#include <string>

using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

class human{
	public:
		int height;
		int weight;
		string name;
	
			string humanName()
		{
			cout << "What is the humans Name? " <<endl;
			cin >>  name;
			return name;
		}	
		
		int humanHeight(string msg)
		{
			cout << "What is " << msg << "'s height in inches? " << endl;
			cin >>  height;
			return height;
		}
		int humanWeight(string msg)
		{
			cout << "What is "<< msg << "'s weight in pounds?" <<endl;
			cin >>  weight;
			return weight;
		}

		
};


int main() {

	human human1;
	human human2;
    string name;
    string name2;
	name = human1.humanName();
	name2 = human2.humanName();
		
	human1.humanHeight(name);
	human2.humanHeight(name2);
 
	
	human1.humanWeight(name);
	human2.humanWeight(name2);
	

	
	cout << "Hi we are " << human1.name << " and " << human2.name << "." <<endl;
	cout << human1.name << " is " << human1.height << " inches tall." << human2.name << " is " << human2.height << " inches tall." <<endl;
	cout << human1.name << " weighs " << human1.weight << " lbs." << human2.name << " weighs " << human2.weight << " lbs."<<endl;
	
	
	return 0;
}
Well I figured out a way to do it. It works for the program. just not sure if there was a alternative solution to my problem. I included a if statement to complete what I wanted it to do.

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
63
64
65
66
67
68
69
70
71
72
#include <iostream>
#include "person.h"
#include <string>

using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

class human{
	public:
		int height;
		int weight;
		string name;
	
			string humanName(int i)
		{
			int counter = i;
			if(counter == 1){
			
			cout << "What is the first human's Name? " <<endl;
			cin >>  name;
			return name;
	    	}
			if(counter == 2){
				cout << "What is the second human's name? " <<endl;
				cin >> name;
				return name;
			}	    
		}	
		
		int humanHeight(string msg)
		{
			cout << "What is " << msg << "'s height in inches? " << endl;
			cin >>  height;
			return height;
		}
		int humanWeight(string msg)
		{
			cout << "What is "<< msg << "'s weight in pounds?" <<endl;
			cin >>  weight;
			return weight;
		}

		
};


int main() {

	human human1;
	human human2;
    string name;
    string name2;
    int counter;
	name = human1.humanName(counter = 1);
	name2 = human2.humanName(counter = 2);
		
	human1.humanHeight(name);
	human2.humanHeight(name2);
 
	
	human1.humanWeight(name);
	human2.humanWeight(name2);
	

	
	cout << "Hi we are " << human1.name << " and " << human2.name << "." <<endl;
	cout << human1.name << " is " << human1.height << " inches tall." << human2.name << " is " << human2.height << " inches tall." <<endl;
	cout << human1.name << " weighs " << human1.weight << " lbs." << human2.name << " weighs " << human2.weight << " lbs."<<endl;
	
	
	return 0;
}
Topic archived. No new replies allowed.