高手们看看 我的代码debug的时候无限循环!!为什么
c++吧
全部回复
仅看楼主
level 1
AUG785😈 楼主
我觉得是for出了问题 但我不知道怎么弄
以下是我的代码
#include<iostream>;
#include<iomanip>;
#include<cmath>;
using namespace std;
int main()
{
double x=0.0;
int rowsnumber=0;
double increment=0.0;
double index=0;
int numberofline=0;
double expx=0.0;
double log10x=0.0;
double sqrtx=0.0;
double startpoint=0.0;
double endpoint=0.0;
do
{cout<<"Enter the number of rows in the table to be produced"<<endl;
cout<<"The number of rows must be between 0 and 35"<<endl;
cin >> rowsnumber;
}
while (rowsnumber<=0 || rowsnumber>=35);
do
{cout<<"Enter the starting X"<<endl;
cout<<"The starting X must satisfy |X| < 100"<<endl;
cin>>x;
}
while(abs(x)>100);
do
{cout<<"Enter the increment in X between successive rows"<<endl;
cout<<"The increment in X must be positive"<<endl;
cin>>increment;
}
while(increment<0);
startpoint=x;
endpoint=x+(increment*rowsnumber);
numberofline=1;
cout<<"X exp(X) log10(X) sqrt(X)"<<endl;
for(startpoint;endpoint;increment)
{ double x=startpoint+((numberofline-1)*increment);
expx=exp(x);
log10x=log10(x);
sqrtx=sqrt(x);
if(x<0)
{ cout<<setw(15)<<x<<setw(15)<<left<<scientific<<expx<<setw(15)<<left<<"undefined"<<setw(15)<<left<<fixed<<setprecision(9)<<sqrtx<<endl;
}
else
{cout<<setw(15)<<x<<setw(15)<<left<<scientific<<expx<<setw(15)<<left<<fixed<<setprecision(9)<<log10x<<setw(15)<<left<<fixed<<setprecision(9)<<sqrtx<<endl;
}
numberofline=numberofline+1;
}
return 0;
}
2014年10月15日 02点10分 1
1