【发布时间】:2016-03-04 04:41:33
【问题描述】:
无法找出我的程序的问题。由于某种原因,我试图计算边距内的限制,我不认为 while 循环正在初始化。我很新手。请帮忙。我不知道我做错了什么。
#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);
}
【问题讨论】:
-
调试是编程的重要组成部分。你有一个很好的学习机会!使用调试器和/或阅读how to debug small programs。另外,how to ask.
-
真正的问题是什么?