POJ之路4--1004Financial Management

一、

Input

The input will be twelve lines. Each line will contain the closing balance of his bank account for a particular month. Each number will be positive and displayed to the penny. No dollar sign will be included.

Output

The output will be a single number, the average (mean) of the closing balances for the twelve months. It will be rounded to the nearest penny, preceded immediately by a dollar sign, and followed by the end-of-line. There will be no other spaces or characters in the output.

很简单的一个题目,不过中间对于一个优先级问题困扰了好久,一步步尝试才找到问题。

temp=((int)(m*100))/100.0+((int)temp/5)*0.01;

temp=((int)m*100)/100.0+((int)temp/5)*0.01;

这两句代码,唯一的区别在于m*100是否加括号,但结果却不同,看来以前对于强制转换的认识有偏差。
比如=1.12,执行 (int)(m*100) 得到112,而执行 (int)m*100得到100。



最终AC的代码如下:
#include<iostream>
using namespace std;

int main()
{
	double money=0;
	float m;
	for(int i=0;i<12;i++)
	{
		cin>>m;
		money+=m;
	}
	m=money/12;
	float temp=(int)(m*1000)%10;
	temp=((int)(m*100))/100.0+((int)temp/5)*0.01;
	cout<<"$"<<temp;

	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值