我是编程新手,今天我开始使用函数。当我尝试编译代码时,我收到此错误消息:
34|错误:无法将参数 '1' 的 'float (*)()' 转换为 'float' 到 'float calculator(float, float, char)'|
问题出在哪里?
#include <iostream>
using namespace std;
//Insert number
float ins_num(){
float num;
cout<<"Insert a number: ";
cin>>num;
return num;
}
//Insert operator
char ins_oper(){
char oper;
do{
cout<<"Insert the operator: ";
cin>>oper;
}
while(oper!='+'&&oper!='-'&&oper!='*'&&oper!='/');
return oper;
}
//Calculator
float calculator(float n1,float n2,char oper){
switch(oper){
case '+':return n1+n2;
case '-':return n1-n2;
case '*':return n1*n2;
case '/':return n1/n2;
}
}
int main(){
calculator(ins_num,ins_num,ins_oper);
}