title: I want to use a variable set in function in main program but errors in declaring variable
body: <p>I have declared and set a variable in a separate .cpp file but not the main file. I want the value given in the function to be used in the main program. I have included below the main file, function file and header file.</p>
  
  <p>main.cpp:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include "create_character.h"
  
  int main() {
    set_gender();
    set_age();
    std::cout &lt;&lt; "Your character is a " &lt;&lt; age &lt;&lt; " year old "
    &lt;&lt; gender &lt;&lt; "." &lt;&lt; std::endl;
  }
  </code></pre>
  
  <p>character.cpp:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include "create_character.h"
  
  std::string set_gender()
  {
    std::string gender;
    std::cout &lt;&lt; "Would you like your character to be male or female? Type m for male or f for female.";
    std::cin &gt;&gt; gender;
  
    if (gender == "m")
    {
      gender = "male";
    }
    if (gender == "f")
    {
      gender = "female";
    }
  }
  
  int set_age() {
    int age;
    std::cout &lt;&lt; "How old is your character?";
    std::cin &gt;&gt; age;
  }
  </code></pre>
  
  <p>character.h:</p>
  
  <pre><code>#include &lt;string&gt;
  
  std::string set_gender();
  int set_age();
  </code></pre>