注册 登录
编程论坛 C++教室

各位大侠帮帮忙啊

yh1 发布于 2007-03-22 00:34, 974 次点击

这是C++书本上的例3-5
我改了一下 但不知道是那里错了 帮忙看一下啊

#include<iostream>
#include<cmath>//c++中的定义数学函数的头文件
using namespace std;
int main()
{
double k,r,s;
double tsin(double x);
cout<<"r=";
cin>>r;
cout<<"s=";
cin>>s;
if(r*r<=s*s)
k=sqrt(tsin(r)*tsin(r)+tsin(s)*tsin(s));
else
k=tsin(r*s)/2;
cout<<k<<endl;
}
double tsin(double x)
{ int a;
double g,b,sqr;
a=1;
g=0;
sqr=x*x;
whlie(fabs(e/a)>le-6) //e/a大于0.000001
{ b=e/a;
g=(e%7==1)?g+b:g-b;
e*=sqr;
a*=(a+2)*(a+1);
}
return g;
}


VC++这样显示的 Compiling...
3-5.cpp
C:\Program Files\Microsoft Visual Studio\MyProjects\3 5\3-5.cpp(17) : warning C4508: 'main' : function should return a value; 'void' return type assumed
C:\Program Files\Microsoft Visual Studio\MyProjects\3 5\3-5.cpp(24) : error C2065: 'whlie' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\MyProjects\3 5\3-5.cpp(24) : error C2065: 'e' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\MyProjects\3 5\3-5.cpp(24) : error C2065: 'le' : undeclared identifier
C:\Program Files\Microsoft Visual Studio\MyProjects\3 5\3-5.cpp(25) : error C2143: syntax error : missing ';' before '{'
执行 cl.exe 时出错.

3 5.exe - 1 error(s), 0 warning(s)

11 回复
#2
PcrazyC2007-03-22 11:33
whlie(fabs(e/a)>le-6)中while写成whlie了,e没有定义,1e写成le 了,不是LE,而是1E
#3
PcrazyC2007-03-22 11:34
int main()
另外 main最好定义为void型
#4
yh12007-03-22 12:56
回复:(PcrazyC)whlie(fabs(e/a)>le-6)中while写...

改成这样子了 还是有错啊

#include <iostream>
#include <cmath>//c++中的定义数学函数的头文件
using namespace std;
void main()
{
double k,r,s;
double tsin(double x);
cout<<"r=";
cin>>r;
cout<<"s=";
cin>>s;
if(r*r<=s*s)
k=sqrt(tsin(r)*tsin(r)+tsin(s)*tsin(s));
else
k=tsin(r*s)/2;
cout<<k<<endl;
}
double tsin(double x)
{ int a;
double e,g,b,sqr;
e=x;
a=1;
g=0;
sqr=x*x;
while (fabs(e/a)>1e-6) //e/a大于0.000001
{ b=e/a;
g=(a%7==1)?g+b:g-b;
e*=sqr;
a*=(a+2)*(a+1);
}
return g;
}


Compiling...
35.cpp
Linking...
LIBCD.lib(wincrt0.obj) : error LNK2001: unresolved external symbol _WinMain@16
Debug/12.exe : fatal error LNK1120: 1 unresolved externals
执行 link.exe 时出错.

12.exe - 1 error(s), 0 warning(s)

#5
PcrazyC2007-03-22 13:10
我在机上编译没有问题,运行时死机
#6
yh12007-03-22 13:32

你用的是VC++????

#7
PcrazyC2007-03-22 13:37
是的
#8
PcrazyC2007-03-22 13:47
哦,是你的算法有问题,效率太低.我将1e-6改成0.01后,一下子就出来了,而原来的等十几秒都没反应
#9
yh12007-03-22 13:51

但是我的vc++就是上面的情况,编译不了

#10
yh12007-03-22 13:53

你是直接COPY这个程序然后粘贴到vc++上??

#11
yh12007-03-22 13:54

是直接COPY还是自己打啊

#12
yh12007-03-22 13:58
谢谢大侠了 我知道原因了 是工程的问题 重建一个就好了
1