C ++编码问题

时间:2015-03-21 22:45:34

标签: c++

我正在尝试编译代码时遇到此错误。我正在尝试制作一个简单的计算器,我在删除这个最终错误时遇到了一些麻烦。任何和所有的帮助表示赞赏。 我得到的错误如下所示:'之前的预期构造函数,析构函数或类型转换('令牌

#include <iostream>
#include <string.h>

using namespace std;

int intevaluate(int Left, char Operation, int Right);
void Intro();

int intLeft;
int intRight;
char charOperation;
int intAddition;
int intSubtraction;
int intMultiplication;
int intDivision;


void Intro()
{
cout << "These are the arithmetic operations you can choose to enter ";
cout << " + for addition\n - for subtraction\n * for multiplication\n and / for division\n";
}

intevaluate(intLeft, charOperation, intRight)
{
intAddition = intLeft + intRight;
intSubtraction = intLeft - intRight;
intMultiplication = intLeft * intRight;
intDivision = intLeft / intRight;


if (charOperation == "+")
{
cout << "The answer is " << intAddition;
}

else if (charOperation == "-")
{
cout << "The answer is " << intSubtraction; 
}

else if (charOperation == "*")  
{ 
cout << "The answer is " << intMultiplication;
}

else if (charOperation == "/") && ( Left || Right != 0)
{
cout << "The answer is " << intDivision;
}

else if (charOperation == "/") && ( Left || Right == 0)
{
cout << "You cannot divide by zero ";
}

}









int main()
{
cout << "Please enter an integer value and press enter: ";
cin >> intLeft;

cout << "\nPlease enter another integer value and press enter: ";
cin >> intRight;

Intro();

cout << "\nPlease enter an arithmetic operation from the list above and  press enter: ";
cin >> charOperation;


intevaluate(intLeft, charOperation, intRight);

return 0;
}

1 个答案:

答案 0 :(得分:2)

你搞砸了函数参数名称。

if (Operation == +)
{
    // ...
}

什么是操作?您将函数传递给参数名称为

的char
charOperation

不     操作

你无法比较那样的人物。你必须

if(charOperation == '+')

等等。