函数未声明简单程序

function not declared simple program

本文关键字:程序 简单 未声明 函数      更新时间:2023-10-16

大家好,我相信有人可以帮助我,我对c ++很陌生,试图使这个程序工作。当我从我的主函数调用我的 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;
}

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

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

multifunction也与multiFunction不同。

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

拼写

错误:

total = multifunction(value1, value2);

应该是:

total = multiFunction(value1, value2, OP);

主要函数应该是:

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;
}