Q:

Getting identifier choice is undefined

I'm working on a calculator console app. I'm a beginner in C++ I want the program to ask a question after I'm done printing the previous result. I get the following error though and I have no idea how to fix it. 

identifier "choice" is undefined

Here is my source code:
#include "stdafx.h"
#include <iostream>

int getUserInput() {

    std::cout << "Please enter an integer: ";
    int value;
    std::cin >> value;
    return value;
}

int getConversionFormula() {

    std::cout << "What do you want to convert? (1 for Meters to feet, 2 for kilometers to miles, 3 for kilagrams to pounds.): ";

    int op;

    std::cin >> op;

    //user might select an invalid operation that isnt there
    //Implement a way to avoid this. 
    return op;
}

int getUserInput2() {
    std::cout << "Do you want to convert anything else? (hit 1 for yes, hit 2 for no): ";

    int choice; //for the user if they hit yes or no to the question above.

    std::cin >> choice;

    return choice;
}

int getUserChoice(int choice) {

    //If user selects 1 show the converstion formula screen
    if (choice == 1)
        getConversionFormula();
    if (choice == 2)
        std::exit;

    return -1;
}

int calculateResult(int x, int op) {

    //we will use == to compare two variables to see if they are true or not 
    if (op == 1)
        return x * 3.280839895; //meters to feet
    if (op == 2)
        return x / 1.609344; //km to miles
    if (op == 3)
        return x * 2.2046; //kg to pounds

    return -1; //If the user entered an invalid operation
}

void printResult(int result) {

    std::cout << "Your result is: " << result << std::endl;
}
int main()
{
    int input1 = getUserInput();   //Gets the users input

    int op = getConversionFormula();

    int result = calculateResult(input1, op);

    printResult(result);

    int input2 = getUserInput2(); //Asks the user if they want to convert anything else

    int input3 = getUserChoice(input2, choice);
    std::cin.clear(); // reset any error flags
    std::cin.ignore(32767, '\n'); // ignore any characters in the input buffer until we find an enter character
    std::cin.get(); // get one more char from the user
}

Can someone please tell me how I can fix it? I get the error in the main function just to let everyone know.

A:

choice is not declared in main, it's only in getUserInput2, which it returns. getUserChoice doesn't even take two arguments, so just do:
getUserChoice(input2);

You could start chaining your function calls a bit, e.g.: getUserChoice(getUserInput2()); and thus eliminate a few local variables.

