如何在Ada中编写人口增长表?

问题描述

**我希望我的代码显示针对人口的下表,但似乎我的代码不是 甚至接近这个。那么如何正确编写代码?我最大的问题是使用基于范围的 for循环。该表显示了A和B的人口及其人口增长(百分比), 要求用户输入一些数据,当总体b绕过总体a时,循环应 停。示例代码:**

Enter start year: 1976
Enter country A's population (in million): 200
Enter country A's population increase (in%): 10.0
Enter country B population (in million): 100
Enter country B population increase (in%): 50.0
Year Increase A  Population A  Increase B  Population B
1976  ----        200.00        ------       100.00
1977 20.00        220.00        50.00        150.00
1978 22.00        242.00        75.00        225.00
1979 24.20        266.20        112.50       337.50
In 1979,country B bypassed country A in population.

我的代码:

with Ada.Text_IO;                    use Ada.Text_IO;
with Ada.Integer_Text_IO;            use Ada.Integer_Text_IO;
with Ada.Float_Text_IO;              use Ada.Float_Text_IO;

procedure Population is
x,Population_A,Population_B:Float;
Growth_A,Growth_B,Growth_1,Growth_2: Float;
begin
Put("Write in the year: "); Get(x);
Put("Population_A: "); Get(Population_A);
Put("Population_B: "); Get(Population_B);
Put("Population grow for A: "); Get(Growth_A);
Put("Population growth for B: "); Get(Growth_B); New_Line;

Put("Year   Growth A   Population A   Growth B    Population B ");
for I in 1900..2018 loop
  Put(Integer(I)); New_Line;
  while Population_B < Population_A loop
     Growth_1 := Growth_A +1.0;
     Growth_2 := Growth_B +1.0;
     Put(Growth_1,13,2,0); New_Line;
     Put(Population_A + (Population_A * Growth_A/100.0),15,0); New_Line;
     Put(Growth_2,17,0); New_Line;
     Put(Population_B + (Population_B * Growth_B/100.0),19,0);
     end loop;
end loop;
end Population;

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)