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