函数未声明简单程序

时间:2015-01-16 04:53:06

标签: c++

大家好,我相信有人可以帮助我,我对c ++非常陌生,试图让这个程序正常运行。当我从我的main函数调用我的int函数时,它告诉我它还没有被声明。我在顶部使用了原型,所以我不确定它为什么会挂起。我还缺少任何语法吗? 感谢您的帮助。

#include <iostream>

using namespace std;

int multiFunction(int, int, char);

int main()
{
    int value1, value2, OP, total;

    total = multifunction(value1, value2);
    cout << "Enter a simple math problem I will solve it for you:";
    cin >> value1 >> OP >> value2;                  //gets the three values
    cout << "The answer is: " << total << end       //displays the answer
    return 0;
}

int multiFunction(int A, int B, char OP)
{
    int C;                         //Holds the integer after the operation.
    switch(OP)
    {
    case '+':
        C = A + B;
        break;
    case '-':
        C = A - B;
        break;
    case '*':
        C = A * B;
        break;
    case '/':
        C = A / B;
    }
    return C;

}

3 个答案:

答案 0 :(得分:5)

您没有在此传递第三个参数:

 total = multifunction(value1, value2);   //Prototype is int multiFunction(int, int, char);

同样multifunctionmultiFunction不同。

int aint A是2个唯一变量。类似的规则适用于方法。

答案 1 :(得分:1)

拼写错误:

total = multifunction(value1, value2);

应该是:

total = multiFunction(value1, value2, OP);

答案 2 :(得分:1)

主要功能应该是:

int main()
{
    int value1, value2, total;
    char OP; 

    cout << "Enter a simple math problem I will solve it for you:";

    cin >> value1 >> OP >> value2;                  //gets the three values

    total = multiFunction(value1, value2, OP);
                                       // ^^
    cout << "The answer is: " << total << end       //displays the answer
    return 0;
}