2014-11-06 102 views
-3

我必须制定计算每年国家人口的计划。 在2014年,人口是x,2015年是x *(12%),每年增加12%。 我tryed做到这一点的方式,但通过它无法得到:计算产品累积和的麻烦

#include<iostream> 

using namespace std; 
int main(){ 
int year; 
double pop=344000 

    cout<<"Year of population: "; 
cin >> year; 

switch(year){ 
case 2014: cout<< "344000\n"; 
break; 
case 2015: cout<< pop+=* 0.12 + pop ; //last year pop *0.12+ last year pop 
break; 
cout <<year; 


} 
system("pause"); 
return year; 

} 

我知道它的一个烂摊子,但我真的我12我在C++

+2

这是什么:'year + = * 0.12'? – 2014-11-06 10:48:11

+1

请修复您的标题 – 2014-11-06 10:48:30

+0

您只需要'year + =(year * 0.12)' – ha9u63ar 2014-11-06 10:49:10

回答

0

增量未来year`s人口小白最后一个百分比,我们检查了多少年通过并增加与无需人口为开关

int main(){ 
    int year; 
    int baseYear=2014; 
    int dif; 
    int population=2000; //number of people in 2014 

     cout<<"Year of population: "; 
     cin >> year; 
     dif=year-baseYear 
     for(int i=0;i<dif;i++) 
     population+= ((0.12)*population) 
     cout << population; 


    } 
0

我希望看着这个代码将帮助你取消了解你缺少的东西。

include<iostream.h> 
void main() 
{ 
    int population= 3000000; 
    int year; 
    cout<<"Enter a year greater than or equal to 2014 "; 
    cin>>year; 

    if(year<2014) 
    cout<<"year must be greater than or equal to 2014"; 
    elseif(year==2014) 
    cout<<population; 
    else 
    { 
    int i=2014; 
    while(i<=year) 
    { 
     population=population*1.12; 
     i++; 
    } 
    cout<<"population"; 
    } 
}