COMP2243 - Programming and Problem Solving

Syllabus Software Installation Assignments Tests
Lectures and Labs
**Back to Full Menu**

Repetitions/Loops WhileLoop.java LoopWithCounter.java LoopWithSentinel.java LoopWithFlag.java SimpleInterest.java Factorial.java Fibnonacci.java PrimeNumber.java GCD.java PopulationGrowth.java ForLoop.java DoWhileLoop.java FileIO_Tickets.java FileIO_Salary.java NestedLoop.java



PopulationGrowth Program


Description

Two schools have different populations and projected growth rates. Assume that school one has less population than school two, but has higher projected growth rate.

This program determines the number of years school one will have greater population than school two.

Associated Concepts:

while loop

Algorithm:

Input populations and projected growth rates for school one and school two

Set the variable year to 0

Use a while to check the relation between population one and population two
(as long as population one is less than population two)

    Calculate the new populations of both schools by incorporating the growth rates for the next year

    Increment the variable year by 1

Once the while loop is ended, the variable year holds the answer.

Source Code



Sample Run



Video