if i make a class with private variables and i make public member functions to populate those private variables, can i populate the variable and return the variable in the same member function and how would i do that? Or do i have to make two separate member functions, 1 to store the variable and 1 to return it. For example,
Populate is probably the wrong word. I'd use "set" or "initialize" (if it was the first time value set)
and yes you could do both in the one member function. like this:
class CarData
{
private:
int year;
public:
int CarData::SetYearandReturn(int year1);
};
int main()
{
return EXIT_SUCCESS;
};
int CarData4::SetYearandReturn(int year1)
{
year = year1;
return year;
}
ok take a look at this and tell me what's wrong. It only outputs the last year the user input ever how many times the elementLength - 1 is to the screen instead of say getting 1990 2000 2005 i get 2005 2005 2005