一个c++ 程序编译通不过,请高手查查原因

帅86 2009-01-08 05:35:38
#include <iostream>
using std::cout;
using std::endl;
using std::fixed;
#include <iomanip>
using std::setw; // enables program to set a field width
using std::setprecision;

#include <cmath> // standard C++ math library
using std::pow; // enables program to use function pow

int main()
{
double amount; // amount on deposit at end of each year
double principal = 1000.0; // initial amount before interest
double rate = .05; // interest rate

// display headers
cout << "Year" << setw( 21 ) << "Amount on deposit" << endl;

// set floating-point number format
cout << fixed << setprecision( 2 );

// calculate amount on deposit for each of ten years
for ( int year = 1; year <= 10; year++ )
{
// calculate new amount for specified year
amount = principal * pow( 1.0 + rate, year );

// display the year and the amount
cout << setw( 4 ) << year << setw( 21 ) << amount << endl;
} // end for

return 0; // indicate successful termination
} // end main
...全文
118 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
xiaoniba10631 2011-08-30
  • 打赏
  • 举报
回复
2008下边是好的!
nullah 2009-01-08
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 hunanwy 的回复:]
那该怎么改 啊
[/Quote]
换编译器 不要因为编译器浪费了你的时间
帅86 2009-01-08
  • 打赏
  • 举报
回复
哦,
谢谢了
nullah 2009-01-08
  • 打赏
  • 举报
回复
VS2005下编译运行通过
up~~
帅86 2009-01-08
  • 打赏
  • 举报
回复
那该怎么改 啊
flydream1980 2009-01-08
  • 打赏
  • 举报
回复
知道了,楼主用的环境一定是 VC6.0的环境。库比较旧了。
换个新环境应该不用改。
帅86 2009-01-08
  • 打赏
  • 举报
回复

我用的是vc6.0

编译器编译时出现下边的提示:
ompiling...
fig05_06.cpp
C:\Documents and Settings\HP\桌面\c++\examples\ch05\Fig05_06\fig05_06.cpp(13) : error C2039: 'pow' : is not a member of 'std'
C:\Documents and Settings\HP\桌面\c++\examples\ch05\Fig05_06\fig05_06.cpp(13) : error C2873: 'pow' : symbol cannot be used in a using-declaration
执行 cl.exe 时出错.

fig05_06.obj - 1 error(s), 0 warning(s)
flydream1980 2009-01-08
  • 打赏
  • 举报
回复
using std::pow; error: namespace "std" has no member "pow"

#include <iostream> 
using std::cout;
using std::endl;
using std::fixed;
#include <iomanip>
using std::setw; // enables program to set a field width
using std::setprecision;

#include <cmath> // standard C++ math library
//using std::pow; // enables program to use function pow

int main()
{
double amount; // amount on deposit at end of each year
double principal = 1000.0; // initial amount before interest
double rate = .05; // interest rate

// display headers
cout << "Year" << setw( 21 ) << "Amount on deposit" << endl;

// set floating-point number format
cout << fixed << setprecision( 2 );

// calculate amount on deposit for each of ten years
for ( int year = 1; year <= 10; year++ )
{
// calculate new amount for specified year
amount = principal * pow( 1.0 + rate, year );

// display the year and the amount
cout << setw( 4 ) << year << setw( 21 ) << amount << endl;
} // end for

return 0; // indicate successful termination
} // end main
baihacker 2009-01-08
  • 打赏
  • 举报
回复

我的通过了
d:\>g++ test.cpp
test.cpp:35:15: warning: no newline at end of file

d:\>a
Year Amount on deposit
1 1050.00
2 1102.50
3 1157.63
4 1215.51
5 1276.28
6 1340.10
7 1407.10
8 1477.46
9 1551.33
10 1628.89

65,210

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧