我得到了類型'float'和'int'的錯誤無效操作數到二進制'運算符^',我不是知道如何解決它錯誤:類型'浮動'和'int'到二進制'運算符'的無效操作數''
在函數f出現的錯誤,在最後一行
任何幫助深表感謝
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;
float f(float x);
int main()
{
float a;
float b;
int n;
float h;
float x;
float area;
cout << "Please input the first limit: ";
cin >> a;
cout << "Please input the second limit: ";
cin >> b;
cout << "How many rectangles do you want to use? ";
cin >> n;
h = (b-a)/n;
area = (f(a)+f(b))/2;
for (int i=1;i<n;i++) {
area += f(a+i*h);
}
area = area*h;
cout << "The area under the curve of f(x) = (2/sqrt(3.14))(exp(-x^2)) is ";
cout << area;
}
float f(float x){
return (exp(-x^2))(2/sqrt(3.14));
}
'exp(-x^2)'不符合你的想法。 – drescherjm