/*Problem D 我想有套北京的房
Description
小原是一個軟件工程師,名叫原黛瑪,他在北京工作。現在有一套房子,價格200萬,房價每年上漲10%,
每年固定能賺40萬。他想知道要想買下這套房子,不貸款,不漲工資,沒有其他收入,
每年不吃不喝不消費,20年之內是否能攢夠錢買下這套房子?
Input
房子的價格(萬),房價上漲率,每年收入(萬)。
Output
20年之內是否能買下房子的結論,能買下輸出'Y',買不起輸出'N'。
Sample Input
200 0.1 40
Sample Output
N
*/
/*copyright (c) 2013,煙臺大學計算機學院
*All rights reserved.
*作者:趙振凱
*完成日期:2013年11月21日
*版本號:v1.0
*問題描述:房價
*/
#include <iostream>
#include<cstdio>
using namespace std;
int main( )
{
double money; //N年一共擁有的錢 。
double houseprice,rate, salary;
cin>> houseprice>>rate>>salary;//輸入房價,利率,年收入。
money=salary;
int year=1;
while(year<=20&&money<houseprice)
{
houseprice*=(1+rate);
money+=salary;
year++;
}
if(year>20)
cout<<"N"<<endl;
else
cout<<"Y"<<endl;
return 0;
}
運行結果:
心得體會:
剛開始忘記打=號了。。。最後還可以。