Temperature Conversion Program I'm having trouble accessing variables throughout multiple functions. For example, I need to use userinput throughout many other functions, but do not have access to it with my current code. I am pretty sure that I need to change the parameters of my functions, so that I can pass the value of those functions by reference, but I'm having trouble doing that. 

Here's what my code looks like right now: 

#include &lt;cstdlib&gt;
#include &lt;iostream&gt;
#include &lt;cmath&gt;
#include &lt;iomanip&gt;

using namespace std;

double fahrtocels();
double celstofahr();
double celstokelv();
double kelvtocels();


int main()
{
    do { int userinput=0;

    cout &lt;&lt; " 1) Fahr to Cels" &lt;&lt; endl;
    cout &lt;&lt; " 2) Cels to Fahr" &lt;&lt; endl;
    cout &lt;&lt; " 3) Cels to Kelv" &lt;&lt; endl;
    cout &lt;&lt; " 4) Kelv to Cels" &lt;&lt; endl;
cin &gt;&gt; userinput;
if(userinput=1)
fahrtocels();
if(userinput=2)
celstofahr();
if(userinput=3)
celstokelv();
if(userinput=4)
kelvtocels(); } while(userinput=0);

}

double fahrtocels()
{
    int input;
    int tempinput;
    double finaloutput;
    cout &lt;&lt;" Please Enter the Temp in Fahrenheit"&lt;&lt;endl;
    cin &gt;&gt; input;
userinput= 1;
    tempinput = input - 32;

finaloutput = tempinput/1.8;

    cout&lt;&lt;input&lt;&lt; " degrees fahrenheit is equivalent to  " &lt;&lt; finaloutput&lt;&lt; "  celsius"&lt;&lt; endl;
    userinput = 0;
}

double celstofahr()
{
    int inputcels;
    int tempinputcels;
    double finaloutputcels;
    cout &lt;&lt;" Please Enter the Temp in Celsius"&lt;&lt;endl;
    cin &gt;&gt; inputcels;

    tempinputcels = inputcels * 1.8;

finaloutputcels = tempinputcels + 32;

    cout&lt;&lt;inputcels&lt;&lt; " degrees celsius is equivalent to  " &lt;&lt; finaloutputcels&lt;&lt; "  fahrenheit"&lt;&lt; endl;
}

double celstokelv()
{
    int inputcelskelv;
    double finaloutputcelskelv;
    cout &lt;&lt;" Please Enter the Temp in Celsius for Kelvin Conversion"&lt;&lt;endl;
    cin &gt;&gt; inputcelskelv;

finaloutputcelskelv = inputcelskelv + 273.15;

    cout&lt;&lt;inputcelskelv&lt;&lt; " degrees celsius is equivalent to  " &lt;&lt; finaloutputcelskelv&lt;&lt; " kelvin"&lt;&lt; endl;
}

double kelvtocels()
{
    int inputkelvcels;
    double finaloutputkelvcels;

    cout &lt;&lt;" Please Enter the Temp in Kelvin for Celsius conversion"&lt;&lt;endl;
    cin &gt;&gt; inputkelvcels;

finaloutputkelvcels = inputkelvcels - 273.15;

    cout&lt;&lt;inputkelvcels&lt;&lt; " degrees kelvin is equivalent to  " &lt;&lt; finaloutputkelvcels&lt;&lt; " celsius"&lt;&lt; endl;
}
First, the code is technically off-topic, since it has a pretty clear bug (in main):

} while(userinput=0);


This is almost certainly intended to be userinput==0. As-is, it's an assignment, which yields 0, which is treated as false, so the loop only ever executes once, regardless of input from the user.

While I agree with the basic approach @Konrad has advocated, putting together a table of the data needed for the conversions, I think I'd implement it just a bit differently. I would not use std::pair. I'd explicitly define a struct so the values would have meaningful names:

struct conversion {
    double offset;
    double coefficient;
};


Then your conversion would look like:

double convert(conversion_type conversion, double input) { 
   conversion c = conversions[conversion];
   return (input+c.offset)*c.coefficient;
}


...which seems more readable, at least to me. If you do want to maintain separate functions for each conversion, I'd still break things up into one function doing input. another doing the conversion itself, and a third to display the result. I'd still make it largely table drive, using a vector (or array) of pointers to functions, using the number entered by the user to to index into that (after assuring that it's within range, of course).