找不到我的程序問題。我試圖計算邊緣內的限制,由於某種原因,我不認爲while循環正在初始化。我很新手。請幫忙。我不知道我做錯了什麼。編碼找到x^2的限制C++
#include <iostream>
#include <iomanip>
#include <cmath>
double f(double);
using namespace std;
void main()
{
//main program variable declarations
double x_0, h, prev, newapprox, diffapprox; double const tol = 0.000001;
cout << setiosflags(ios::showpoint | ios::fixed) << setprecision(7);
cout << "\n Enter the value at which the limit will be calculated: ";
cin >> x_0;
h = 1;
prev = f(x_0 + h);
cout << "\n x0+h" << setw(25) << "f(x0+h)" << endl;
cout << x_0 + h << setw(25) << prev << endl;
newapprox = f(x_0 + h/2);
cout << x_0 + h/2 << setw(25) << newapprox << endl;
diffapprox = fabs(prev - newapprox);
while (diffapprox > .00001);
{
prev = newapprox;
cout << "\n x0+h" << setw(25) << "f(x0+h)" << endl;
cout << x_0 + h << setw(25) << prev << endl;
newapprox = f(x_0 + h);
cout << x_0 + h << setw(25) << newapprox << endl;
diffapprox = fabs(prev - newapprox);
h /= 2;
}
if (fabs(diffapprox) <= 0.00001)
{
cout << "\n\n The limit exists and has the value" << diffapprox;
}
else
{
cout << "\n\n The limit does not exist at " << x_0;
}
system("pause");
}
double f(double x_0)
{
return pow(x_0, 2.0);
}
調試是編程的重要部分。你有一個很好的學習機會!使用調試器和/或閱讀[如何調試小程序](http://ericlippert.com/2014/03/05/how-to-debug-small-programs/)。另外,[如何問](http://stackoverflow.com/help/how-to-ask)。 –
實際問題是什麼? –