无法从方法调用两个变量到主C ++

时间:2015-10-02 21:57:40

标签: c++ methods

我遇到一个非常简单的程序有问题。我需要在main之外调用一个方法(getNumber),该方法从用户获取两个数字,然后存储这些数字。然后将这两个数字用于计算方法(数学),也称为main。我从getNumber调用的两个数字中得到一个未初始化的局部变量。我希望用户输入两个数字,将它们添加到一起并显示结果但是通过调用方法。

#include <iostream>
#include <string>

using namespace std;

int getNumber(int x, int y)
{
    // here is where the user is prompted to input two numbers
    cout << "Please enter two values" << endl;
    cin >> x >> y;
    return x, y;
}

int math(int x , int y)                             // here is where the    calculations are done
{
    int result;
    result = x + y;
    return result;
}

int main()
{
    int x;
    int y;
    int result;

    x = getNumber(x, y);     // trying to call in the input method here
    result=math(x,y);       // calling in claculation method
    cout << result;
    system("pause");
    return 0;
}

1 个答案:

答案 0 :(得分:1)

connection.query(query1,function(err,rows) {
    var response = [];
    //doing something with rows
    Promise.all(rows.map(function(item) {
        var promise = new Promise(function(resolve,reject) {
            connection.query(queryItem,function(err,rows) {
                //doing something
                result = rows[0].field;
                //and want to push it to an array
                resolve(result);
            });
        });
        return promise.then(function(result) {
            console.log(result); //ok
            response.push(result) //ok
        });
    }).then(function () {
        console.log(response); //not empty
    });
});