标题:基础问题
只看楼主
nala
Rank: 1
等 级:新手上路
帖 子:16
专家分:0
注 册:2006-9-2
 问题点数:0 回复次数:3 
基础问题

#include <iostream>

using std::cin;
using std::cout;
using std::endl;
using std::ios;
using std::fixed;

#include <iomanip>
using std::setw;
using std::setprecision;

#include <cmath>// using pow in maths

int main()
{
double amount;//amount on deposit
double princible = 1000.0;//starting princible
double rate = 0.1;//record rate

//out put table column heads
cout << " YEAR " << setw(21) << " Amount on deposit " << endl;
cout << fixed << setprecision(2);//这句话到底起到什么作用,它又是怎么起作用的呢~?

//calculate
for( int year = 1; year <= 10; year++ ){
amount = princible*pow(1.0 + rate,year);

//output table row
cout << setw(4) << year
<< setw(21) << amount << endl;
}//end for

return 0;//indicate successful termination
}//end function main

搜索更多相关主题的帖子: 基础 
2006-09-13 08:36
雨夜微醺
Rank: 1
等 级:新手上路
威 望:1
帖 子:147
专家分:0
注 册:2006-9-25
得分:0 
确定浮点数精度.

我若想到你就有种莫名的开心 我一见到你就有种莫名的悸动
2006-09-27 18:31
majia775
Rank: 1
等 级:新手上路
威 望:2
帖 子:94
专家分:0
注 册:2006-9-11
得分:0 
程序结果是每个数都保留小数后面两位,setprecision英文就是设置精度的意思.

[此贴子已经被作者于2006-9-27 19:03:41编辑过]



我不是随便的人,我随便起来不是人.... http://majia775.
2006-09-27 19:03
冷血无情
Rank: 1
等 级:新手上路
帖 子:29
专家分:0
注 册:2006-9-25
得分:0 
setprecision(2)就是要设置小数点后两位

2006-09-29 21:36



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-89809-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.208515 second(s), 7 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved