Apr 29, 2016 at 9:59pm UTC
Everything seems to be working, except the final output. Can someone help find my issue somewhere please?
#include <iostream>
#include <string>
using namespace std;
class Population
{
public:
int pop, births, deaths;
int birth_rate();
int death_rate();
}values;
int Population::birth_rate()
{
return births/pop;
}
int Population::death_rate()
{
return deaths/pop;
}
int main()
{
Population values;
cout <<"Enter the population: ";
cin >> values.pop;
cout<< "Enter the number of births: ";
cin >> values.births;
cout << "Enter the number of deaths: ";
cin >> values.deaths;
values.birth_rate();
values.death_rate();
cout << "Birth rate: "<< values.birth_rate()<< endl;
cout << "Death rate: " << values.death_rate() << endl;
return 0;
}
Apr 29, 2016 at 10:13pm UTC
its because your functions return an int rather than a double or float.
try changing your variables and functions to doubles
Apr 29, 2016 at 10:16pm UTC
Use code tags when posting code. Edit your post.
As for your problem, I think you should use double
for the variables pop, birth, deaths, but also for the functions. Since you haven't explained thoroughly your problem, this is my only guess as to why there is wrong output.