这个错误如何修改
这行出错:g=x+y;
显示错误如下:
[Error] 'x' was not declared in this scope
如何修改?代码如下:
程序代码:
#include<iostream> using namespace std; int g; double (*add)(double x,double y){ g=x+y; return g; } double calculate(double x,double y,double *ar){ double *p=new double; p=(*ar)(x,y); return *p; } int main(void){ double j,k; while(1){ cout<<"请输入j,k的值:"; while(!(cin>>j)||!(cin>>k)){ cin.clear(); while(cin.get()!='\n'); continue; cout<<"错误,输入的是字母,请输入数字:\n"; } (*add)(j,k); double h=calculate(j,k,add); cout<<"calculate函数的返回值为:"<<h<<endl; delete p; } return 0; }
[此贴子已经被作者于2020-12-10 19:30编辑过]