gpt4 book ai didi

c++ - 函数未声明简单程序

转载 作者:太空宇宙 更新时间:2023-11-03 10:43:40 24 4
gpt4 key购买 nike

大家好,我相信有人可以帮助我,我是 c++ 的新手,试图让这个程序工作。当我从我的 main 函数调用我的 int 函数时,它告诉我它还没有被声明。我在上面使用了一个原型(prototype),所以我不确定它为什么会挂起。我还缺少任何语法吗?提前感谢您的帮助。

#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);

此外,multifunctionmultiFunction 不同。

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

关于c++ - 函数未声明简单程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27977503/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com