Untitled

 avatar
unknown
plain_text
a year ago
2.0 kB
3
Indexable
#include <iostream>

using namespace std;

int main() {
    // Input population and growth rate for Lahore
    int lahorePopulation;
    double lahoreGrowthRate;
    int karachiPopulation;
    double karachiGrowthRate;

    do {
        cout << "Enter the population of Lahore: ";
        cin >> lahorePopulation;

        cout << "Enter the growth rate of Lahore (in percentage): ";
        cin >> lahoreGrowthRate;

        cout << "Enter the population of Karachi: ";
        cin >> karachiPopulation;

        cout << "Enter the growth rate of Karachi (in percentage): ";
        cin >> karachiGrowthRate;

        if (lahorePopulation >= karachiPopulation || lahoreGrowthRate <= karachiGrowthRate) {
            cout << "Invalid input data. Lahore population should be less than Karachi population and Lahore growth rate should be higher than Karachi growth rate." << endl;
        }
    } while (lahorePopulation >= karachiPopulation || lahoreGrowthRate <= karachiGrowthRate);

    // Calculate the number of years for Lahore's population to surpass Karachi's population
    int years = 0;
    while (lahorePopulation < karachiPopulation) {
        lahorePopulation += lahorePopulation * (lahoreGrowthRate / 100);
        karachiPopulation += karachiPopulation * (karachiGrowthRate / 100);
        years++;
    }

    // Calculate the total population of both cities at that time
    int totalPopulation = lahorePopulation + karachiPopulation;

    // Print the results
    cout << "Lahore population will surpass Karachi after " << years << " years." << endl;
    cout << "Total population of Lahore at that time: " << lahorePopulation << endl;
    cout << "Total population of Karachi at that time: " << karachiPopulation << endl;
    cout << "Lahore will have " << lahorePopulation - karachiPopulation << " more people than Karachi." << endl;
    cout << "Total population would be " << totalPopulation << "." << endl;

    return 0;
}