0

私のコードが出生率と死亡率を計算しない理由がわかりません。私は両方とも0を取得し続けます。static_cast<double>これが起こらないようにするために を含めました。フィードバック / ヘルプはありますか?

#include <iostream>
#include <string>
using namespace std;

double calculateBirthRate();
double calculateDeathRate();

class PopInfo
{
    private:
        string cityName;
        long totalCityPopulation;
        int numberOfBirths;
        int numberOfDeaths;
        double birthrate;
        double deathrate;
        int bir;
        int dea;
        long citpop;

    public:
        PopInfo()
    {
        cityName = "";
        totalCityPopulation = numberOfBirths = numberOfDeaths = 0;
    }

    long getPopulation()
    {
        return totalCityPopulation;
    }

    int getBirths()
    {
        return birthrate;
    }

    int getDeaths()
    {
        return deathrate;
    }

    string getCity()
    {
        return cityName;
    }

    void setCityName(string nameOfCity)
    {
        cityName = nameOfCity;
    }

    void setTotalCityPopulation(long populationOfCity)
    {
        totalCityPopulation = populationOfCity;
    }

    void setNumberOfBirths(int birthNumbers)
    {
        numberOfBirths = birthNumbers;
    }

    void setNumberOfDeaths(int deathNumbers)
    {
        numberOfDeaths = deathNumbers;
    }

    void calculateBirthRate(PopInfo);
    void calculateDeathRate(PopInfo);

};

int main()
{
    PopInfo newCity;

    string cit;
    long citpop;
    int bir;
    int dea;


   cout << "What is the city name?: " << endl;
   cin >> cit;
   cout << "What is the total city population?: " << endl;
   cin >> citpop;
   while (citpop < 1)
   {
       cout << "Please enter a valid total city population: " << endl;
       cin >> citpop;
   }
   cout << "What are the number of births?: " << endl;
   cin >> bir;
   while (bir < 0)
   {
       cout << "Please enter a valid number of births: " << endl;
       cin >> bir;
   }
   cout << "What are the number of deaths?: " << endl;
   cin >> dea;
   while (dea < 0)
   {
       cout << "Please enter a vaild number of deaths: " << endl;
       cin >> dea;
   }

   newCity.setCityName(cit);
   newCity.setTotalCityPopulation(citpop);
   newCity.setNumberOfBirths(bir);
   newCity.setNumberOfDeaths(dea);

    cout << endl;
    cout << "The city name is " << newCity.getCity() << endl;
    cout << "The total city population is " << newCity.getPopulation() << endl;
    cout << "The birth rate is " << newCity.getBirths() << endl;
    cout << "The death rate is " << newCity.getDeaths() << endl;

   return 0;
}


void PopInfo::calculateBirthRate(PopInfo newCity)
{
    double birthrate = static_cast<double>(newCity.bir) / newCity.citpop;
}

void PopInfo::calculateDeathRate(PopInfo newCity)
{
    double deathrate = static_cast<double>(newCity.dea) / newCity.citpop;
}
4

3 に答える 3