How to return a variable from one function in C++ to main then use it in another function?
<p>Okay so I have a calorie calculator that is supposed to be separated into the five functions including main seen below. My issue is that I get a compiler error because the variables from the inputNumber function and calculateCalories function cannot be read by any of the other functions once they are obtained. I am not allowed to use Global variables. There must be something I am missing to be able to read the variables within the main function then output them into the other functions to get the proper output. Any help would be appreciated.
Here is the code as it stands:</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;iomanip&gt;

using namespace std;

int main()
{
    int Lbs, hourr, hourW, hourWe, hourb;
    double calBad, calRun, calWal, calWei;
    string name;

    cout &lt;&lt; "Welcome to Megan McCracken's Workout Calculator!" &lt;&lt; endl;
    cout &lt;&lt; endl;

    cout &lt;&lt; "Please enter your name: ";
    getline(cin, name);

    inputNumber(Lbs, hourr, hourW, hourWe, hourb);

    calculateCalories(Lbs,hourr,hourb,hourW,hourWe,calBad,calRun,calWal,calWei);

    displayHeadings(name);

    displayLine(hourr,hourb,hourW,hourWe,calBad,calRun,calWal,calWei);

    system("pause");
    return 0;
}

int inputNumber(int Lbs, int hourr, int hourb, int hourW, int hourWe)
{
    cout &lt;&lt; "Please enter your weight: ";
    cin &gt;&gt; Lbs;
    return Lbs;
    cout &lt;&lt; "Please enter the minutes spent playing badminton: ";
    cin &gt;&gt; hourb;
    return hourb;
    cout &lt;&lt; "Please enter the minutes spent running: ";
    cin &gt;&gt; hourr;
    return hourr;
    cout &lt;&lt; "Please enter the minutes spent walking: ";
    cin &gt;&gt; hourW;
    return hourW;
    cout &lt;&lt; "Please enter the minutes spent lifting weights: ";
    cin &gt;&gt; hourWe;
    return hourWe;
    cout &lt;&lt; endl;
}

double calculateCalories(int Lbs, int hourW, int hourb, int hourr, int hourWe, double calBad, double calRun, double calWal, double calWei)
{
    const double Badburn = .044, Runburn = .087, Walkb = .036, Weightb = .042;
    double calBad, calRun, calWal, calWei;
    calBad = (Badburn * Lbs) * hourb;
    calRun = (Runburn * Lbs) * hourr;
    calWal = (Walkb * Lbs) * hourW;
    calWei = (Weightb * Lbs) * hourWe;
    return calBad;
    return calRun;
    return calWal;
    return calWei;
}

void displayHeadings(string name)
{
    cout &lt;&lt; "Here are the results for " &lt;&lt; name &lt;&lt; ": " &lt;&lt; endl;
    cout &lt;&lt; endl;

    cout &lt;&lt; "Activity" &lt;&lt; right &lt;&lt; setw(18) &lt;&lt; "Time" &lt;&lt; right &lt;&lt; setw(10) &lt;&lt; "Calories" &lt;&lt; endl;
    cout &lt;&lt; "--------------------------------------" &lt;&lt; endl;
}

void displayLine(int hourb,int hourr, int hourW, int hourWe, double calBad, double calRun, double calWal, double calWei)
{
    int HB, MB, HR, MR, HW, MW, HWE, MWE, Hour, Min;
    double Calorie;
    HB = (hourb / 60);
    MB = (hourb % 60);
    HR = (hourr / 60);
    MR = (hourr % 60);
    HW = (hourW / 60);
    MW = (hourW % 60);
    HWE = (hourWe / 60);
    MWE = (hourWe % 60);

    Calorie = calBad + calRun + calWal + calWei;
    Hour = (hourb + hourr + hourW + hourWe) / 60;
    Min = (hourb + hourr + hourW + hourWe) % 60;

    cout &lt;&lt; "Badminton" &lt;&lt; right &lt;&lt; setw(14) &lt;&lt; HB &lt;&lt; ":" &lt;&lt; setfill('0') &lt;&lt; setw(2) &lt;&lt; MB &lt;&lt; setfill(' ') &lt;&lt; right &lt;&lt; setw(10) &lt;&lt; setprecision(3) &lt;&lt; fixed &lt;&lt; showpoint &lt;&lt; calBad &lt;&lt; endl;

    cout &lt;&lt; resetiosflags(ios::fixed | ios::showpoint);

    cout &lt;&lt; "Running" &lt;&lt; right &lt;&lt; setw(16) &lt;&lt; HR &lt;&lt; ":" &lt;&lt; setfill('0') &lt;&lt; setw(2) &lt;&lt; MR &lt;&lt; setfill(' ') &lt;&lt; right &lt;&lt; setw(10) &lt;&lt; setprecision(3) &lt;&lt; fixed &lt;&lt; showpoint &lt;&lt; calRun &lt;&lt; endl;

    cout &lt;&lt; resetiosflags(ios::fixed | ios::showpoint);

    cout &lt;&lt; "Walking" &lt;&lt; right &lt;&lt; setw(16) &lt;&lt; HW &lt;&lt; ":" &lt;&lt; setfill('0') &lt;&lt; setw(2) &lt;&lt; MW &lt;&lt; setfill(' ') &lt;&lt; right &lt;&lt; setw(10) &lt;&lt; setprecision(3) &lt;&lt; fixed &lt;&lt; showpoint &lt;&lt; calWal &lt;&lt; endl;

    cout &lt;&lt; resetiosflags(ios::fixed | ios::showpoint);

    cout &lt;&lt; "Weights" &lt;&lt; right &lt;&lt; setw(16) &lt;&lt; HWE &lt;&lt; ":" &lt;&lt; setfill('0') &lt;&lt; setw(2) &lt;&lt; MWE &lt;&lt; setfill(' ') &lt;&lt; right &lt;&lt; setw(10) &lt;&lt; setprecision(3) &lt;&lt; fixed &lt;&lt; showpoint &lt;&lt; calWei &lt;&lt; endl;

    cout &lt;&lt; "--------------------------------------" &lt;&lt; endl;

    cout &lt;&lt; resetiosflags(ios::fixed | ios::showpoint);

    cout &lt;&lt; "Totals" &lt;&lt; right &lt;&lt; setw(17) &lt;&lt; Hour &lt;&lt; ":" &lt;&lt; setfill('0') &lt;&lt; setw(2) &lt;&lt; Min &lt;&lt; setfill(' ') &lt;&lt; right &lt;&lt; setw(10) &lt;&lt; setprecision(3) &lt;&lt; fixed &lt;&lt; showpoint &lt;&lt; Calorie &lt;&lt; endl;
    cout &lt;&lt; endl;
}
</code></pre>