首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

为什么小弟我用c++写的求幂积程序运行结果和小弟我想的不一样,求高人指点

2012-03-29 
为什么我用c++写的求幂积程序运行结果和我想的不一样,求高人指点。我写了一个求指数的程序,为什么在用vc6.0

为什么我用c++写的求幂积程序运行结果和我想的不一样,求高人指点。
我写了一个求指数的程序,为什么在用vc6.0编译之后,运行.exe文件,在输入指数和基数之后,就自动退出了,没有打印现实后面的“。。raised to the power of。。is:”如果输入的是不合格的指数,也不回现实提示“exponent can't be smaller than 0”, 这是为什么呢?
,#include <iostream>
using namespace std;
int main()
{int base, exponent;
 long result=1;
 cout<<"enter the base and exponent:"<<endl;
 cin>>base>>exponent;
 if(exponent<0){
cout<<"exponent can't be smaller than 0"<<endl;
return -1;
 }
 if(exponent>0){
 for(int i=1;i<=exponent;++i)
result=result*base;
 
 }
cout<<base
  <<"raised to the power of "
<<exponent<<"is :"
<<result<<endl;
return 0;
}

[解决办法]
return 0; 当然退出了,换成个cin,或者while(1)等待之类的就可以了。春节还写程序,厉害
 
[解决办法]
你cout了就return,当然退出了

加个cin
[解决办法]
在vs2005上运行没有问题

热点排行
Bad Request.