我不知道为什么会出现此编译错误。我尝试了通常的方法来定义字符串,我也尝试了 std::string 但都没有奏效。另外我认为我尝试打印该功能的方式可能存在问题。
#include "stdafx.h"
#include <iostream>
#include <cmath>
#include <string>
float userInput1() // Defines the inputs from the user
{
using namespace std;
cout << "Please enter first number" << endl;
float number1;
cin >> number1;
return number1;
}
float userInput2() // Defines the inputs from the user
{
using namespace std;
cout << "Please enter second number" << endl;
float number2;
cin >> number2;
return number2;
}
std::string getOperation()
{
using namespace std;
cout<<"Please enter the operator. + - * /" << endl;
std::string userOperator;
cin>>userOperator;
return userOperator;
}
float computeValue(float value1, float value2, std::string operation)
{
using namespace std;
if(operation == '+')
{
cout<< value1 + value2<< endl;
}else if(operation =='-')
{
cout<< value1 - value2<< endl;
}else if(operation =='*')
{
cout<< value1 * value2<< endl;
}else if(operation == '/')
{
cout<< value1 / value2<< endl;
}else
{
cout<< "Please enter: + - * /"<< endl;
}
return 0;
}
int main(){
using namespace std;
computeValue(userInput1(), userInput2(), getOperation());
return 0;
}