0
#include <iomanip>
#include <iostream>
using namespace std;

void calcPopulation(int population, int death, int birth, float birthRate, float deathRate);

int main() {

    int population = 0, death = 0, birth = 0;

    cout << "Enter the total population: ";
    cin >> population;
    if (population <= 2) {
        population = 2;
    }

    cout << "Enter annual number of births: ";
    cin >> birth;
    if (birth < 0) {
        birth = 0;
    }

    cout << "Enter annual number of deaths: ";
    cin >> death;
    if (death < 0) {
        death = 0;
    }
    cout << endl;
    cout << "Population Statistic" << endl;
    cout << endl;

    float birthRate = (birth / population);
    float deathRate = (death / population);

    cout << "Population: " << population << endl;

    calcPopulation(population, death, birth, birthRate, deathRate);

}
void calcPopulation(int population, int death, int birth, float birthRate, float deathRate) {
    cout << fixed;
    cout << "Birth Rate: " << setprecision(3) << birthRate << endl;
    cout << "Death Rate: " << setprecision(3) << deathRate << endl;

}

So I can't get the proper display for birthRate and deathRate. Not sure whats wrong with my code. For the birth and death rate its displaying 0.000. Seems like I properly called the method.

0 Answers0