qq_34270294 于 2016.03.16 15:10 提问

//1
//程序要求是根据指定的时间和通货膨胀率来给出预算值//
#include
using namespace std;
int main()
{
/*
a是通货膨胀率，b是通货膨胀率转为小数，c是开支，d是预算 , cout是每一年，year是总年份*/
double a;
double b;
double c,year;
double d;
int cout = 0;
cin>>a>>c>>year>>d;
b=a/100;
cout<<"%a = "<<b<<endl;
while(cout<=year)
{
c=c+c*b*cout;
cout++;
}
cout<<"the budget is "<<d<<endl;
return 0;
}

``````
``````
``````
``````

3个回答

wojiushiwo945you      2016.03.16 15:17

qq_34270294 算法没看懂吗？我写的不太好！看来while循环这样写不太好吧

qq423399099      2016.03.16 15:25

`````` #include<iostream>
using namespace std;

int main()
{
double a;
double b;
double c,year;
double d;
int out = 0;
cout<< "please input a,c,year,d" << endl;
cin>>a>>c>>year>>d;
b=a/100;
cout<<"%a = "<<b<<endl;
while(out<=year)
{
c=c+c*b*out;
out++;
}
cout<<"the budget is "<<d<<endl;
}
``````
qq_34270294 我已经得到了想要的代码！那请问在程序的可读性方面还要做那些改进

qq_34270294 没错没错～这次真的蠢了！cout确实蛮屌的*^_^*

qq_34270294   2016.03.16 15:42

//1

//程序要求是根据指定的时间和通货膨胀率来给出预算值//
#include
using namespace std;
int main(){
//a是通货膨胀率，b是通货膨胀率转为小数，c是开支，d是预算 , cout是每一年，year是总年份//
double a;
double b;
double c,year;
double d;
int out = 0;
cin>>a;
b=a/100;
cout<<"%a = "< cin>>c>>year;
while(out<=year)
{
d=c+c*b*out;
out++;
cout<<"the budget is "<<d<<endl;
}

return 0;
}

//2

``````
``````