# 计算投资收益2.0版

in steemstem •  21 days ago

int main()

{
float daily, time;
int roi;

cin>>daily;

cout<<"How many days?"<<endl;
cin>>time;

roi=100*(pow(1+daily/100,time)-1);

cout<<"You will make "<<roi<<"% after "<< time <<" days!"<<endl;
}

1. 每天的收益和天数必须要定义成float，虽然他们可以都是整数，反正天数肯定是整数，但一定不能定义为int。因为在我们调用的计算幂的pow函数中，底数和幂都不能是int。至少也得是double，所以干脆都定义为float好了。关于这个问题，在C++网站上有明确的说明。

2. 因为我们只计算收益百分比，所以计算公式跟上次有点不同。首先不用考虑初始投资了，然后还得减掉1。最后，因为要换算成百分数，所以还得乘以100。

3. 收益百分比（roi）可以定义为int，因为如果不需要特别精确的话，取整数就可以了。比方说，知道赚20%就可以了，一般来说，不需要精确到小数点后一位或者两位。

Sort Order:

This post has been voted on by the SteemSTEM curation team and voting trail in collaboration with @curie.

If you appreciate the work we are doing then consider voting both projects for witness by selecting stem.witness and curie!

Congratulations @softmetal! You have completed the following achievement on the Steem blockchain and have been rewarded with new badge(s) :

 You published a post every day of the week

Do not miss the last post from @steemitboard:

 Christmas Challenge - The party continues

Support SteemitBoard's project! Vote for its witness and get one more award!

·

#### Hi @softmetal!

Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your UA account score is currently 2.746 which ranks you at #13107 across all Steem accounts.
Your rank has improved 102 places in the last three days (old rank 13209).

In our last Algorithmic Curation Round, consisting of 235 contributions, your post is ranked at #161.

##### Evaluation of your UA score:
• Only a few people are following you, try to convince more people with good work.