You've only shown us a tiny bit of your program, and your question is very vague.
Do you want to create more functions, each of which returns a single property, e.g. getLast(), getMonth(), etc? Or do you want a single function that passes back all the properties at once?
Is getFirst() a free function? A method of a class?
//InfoString.cpp
//##
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
#include <string>
using std::string;
using std::getline;
void getUserInfo(string& name);
int main(){
string text; //variable to store username
getUserInfo(text);
cout<<"Hello: "<<text<<endl;
return 0; //indicates success
}//end of main
void getUserInfo(string& name){
cout<<"What is your name?\n>>";
getline(cin,name);
}//end function getUserInfo
My program is quite long. I am building a Health Profile.... and First is First Name, Here is the program so far above and below that section.
// set first name
void setFirst ( string first )
// set last name
void setLast( string last )
// set gender
void setGender( string gender )
// set today’s month
void settodaysmonth( string todaysmonth )
// set today’s day
void set todaysday( string todaysday )
// set today’s year
void set todaysyear( string todaysyear )
// set month of birth
void setmonthofbirth( string monthofbirth )
// set day of birth
void setdayofbirth( string dayofbirth )
// set year of birth
void setyearofbirth( string yearofbirth )
// set current age
void currentage( string currentage )
// set weight
void setWeight( string Weight )
// set height
void setHeight( string Height )
{
First = First;
Last = Last;
Gender = Gender;
todaysmonth = todaysmonth
todaysday = todaysday
todaysyear = todaysyear
monthofbirth = monthofbirth
dayofbirth = dayofbirth
yearofbirth = yearofbirth
currentage = currentage
Weight = Weight
Height = Height
} // end function sets all functions
// get first name
string getFirst()
{
return First;
} // end function getFirst
private:
string First; // person's first name
string Last; // person’s last name
string Gender; // person’s gender
string todaysmonth; // current month
string todaysday; // current day
string todaysyear; // current year
string monthofbirth // person’s month of birth
string dayofbirth // person’s day of birth
string yearofbirth // person’s year of birth
string currentage // person’s current age
string Weight // person’s weight in pounds
string Height // person’s height in inches
Good question. I am new to C++ and trying to go by what someone told me. I figured this was wrong but I am working by trial and error. What do I need to do to fix this??
And I have no idea what First=First is supposed to do, I am working on that now. I think those should be if statements.
I don't mean to be harsh, but if you're confused by even simple assignment statements, then you should really be spending more time reading your textbook and/or tutorial. You need to be able to grasp the basics before you write code, otherwise you're going to get nowhere.
Well... that was unexpected. My advice was sincerely meant, and I believe it was sound. I certainly didn't mean to encourage anyone to leave the forum.