【发布时间】:2014-11-06 10:47:24
【问题描述】:
我必须编写一个程序来计算该国每年的人口。 2014 年人口为 x,2015 年为 x*(12%),每年增加 12%。 我试过这样做,但无法通过它:
#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;
}
我知道它一团糟,但我真的是 C++ 的菜鸟
【问题讨论】:
-
这是什么:
year+=* 0.12? -
请修正你的标题
-
你只需要
year += (year*0.12) -
或者,年*1.12
-
这是错误的。首先,您没有存储人口的变量。其次,在
case 2015中,您想与去年的人口相乘,而不是与 YEAR ITSELF (这个year+=* 0.12 + year也是错的,非常错误)