identifier " " is undefined

I am trying to correct this program and keep getting that the identifiers "pop, births, and deaths are unidentified.

This program uses the Population class and calculates the death and birth rates of a city*/
#include <iostream>
#include <iomanip>
using namespace std;

class Population
{
private:
int pop;
int births;
int deaths;

public:
void setPopulation (int);
void setBirths(int);
void setDeaths(int);

int getPopulation();
double getBirthRate();
double getDeathRate();

Population() : pop(0), deaths(0), births(0) {}
};

void Population::setPopulation(int p)
{
pop = p;
}

void Population::setBirths(int B)
{
births = B;
}

void Population::setDeaths(int d)
{
deaths = d;
}

int Population::getPopulation()
{
return pop;
}

double getBirthRate()
{
return births / static_cast<double>(pop);
}
double getDeathRate()
{
return deaths / static_cast<double>(pop);
}


int main()
{
Population Town;
int People;
int Births,
Deaths;

cout << "Enter total population: ";
cin >> People;
while (People < 1)
{ cout << "ERROR: Value has to be greater than 0. ";
cin >> People;
}
Town.setPopulation(People);

cout << "Enter annual number of births: ";
cin >> Births;
while (Births < 0)
{ cout << "ERROR: Value cannot be negative. ";
cin >> Births;
}
Town.setBirths(Births);

cout << "Enter annual number of deaths: ";
cin >> Deaths;
while (Deaths < 0)
{ cout << "ERROR: Value cannot be negative. ";
cin >> Deaths;
}
Town.setDeaths(Deaths);

cout << "\nPopulation Statistics ";
cout << fixed << showpoint << setprecision(3);
cout << "\n\tPopulation: " << setw(7) << Town.getPopulation();
cout << "\n\tBirth Rate: " << setw(7) << Town.getBirthRate();
cout << "\n\tDeath Rate: " << setw(7) << Town.getDeathRate() << endl;

return 0;
}
getBirthRate and getDeathRate are missing Population::
when I made that change I got all theses errors:

1>------ Build started: Project: bland, Configuration: Debug Win32 ------
1>Build started 5/2/2014 8:28:39 PM.
1>InitializeBuildStatus:
1> Touching "Debug\bland.unsuccessfulbuild".
1>ClCompile:
1> program.cpp
1>c:\users\fgmck_000\documents\visual studio 2010\projects\bland\bland\program.cpp(26): error C2065: 'pop' : undeclared identifier
1>c:\users\fgmck_000\documents\visual studio 2010\projects\bland\bland\program.cpp(34): error C2653: 'Pop' : is not a class or namespace name
1>c:\users\fgmck_000\documents\visual studio 2010\projects\bland\bland\program.cpp(36): error C2065: 'deaths' : undeclared identifier
1>c:\users\fgmck_000\documents\visual studio 2010\projects\bland\bland\program.cpp(39): error C2653: 'Pop' : is not a class or namespace name
1>c:\users\fgmck_000\documents\visual studio 2010\projects\bland\bland\program.cpp(41): error C2065: 'population' : undeclared identifier
1>c:\users\fgmck_000\documents\visual studio 2010\projects\bland\bland\program.cpp(44): error C2653: 'Pop' : is not a class or namespace name
1>c:\users\fgmck_000\documents\visual studio 2010\projects\bland\bland\program.cpp(46): error C2065: 'births' : undeclared identifier
1>c:\users\fgmck_000\documents\visual studio 2010\projects\bland\bland\program.cpp(46): error C2065: 'population' : undeclared identifier
1>c:\users\fgmck_000\documents\visual studio 2010\projects\bland\bland\program.cpp(48): error C2653: 'Pop' : is not a class or namespace name
1>c:\users\fgmck_000\documents\visual studio 2010\projects\bland\bland\program.cpp(50): error C2065: 'deaths' : undeclared identifier
1>c:\users\fgmck_000\documents\visual studio 2010\projects\bland\bland\program.cpp(50): error C2065: 'population' : undeclared identifier
1>c:\users\fgmck_000\documents\visual studio 2010\projects\bland\bland\program.cpp(57): error C2065: 'Pop' : undeclared identifier
1>c:\users\fgmck_000\documents\visual studio 2010\projects\bland\bland\program.cpp(57): error C2146: syntax error : missing ';' before identifier 'myTown'
1>c:\users\fgmck_000\documents\visual studio 2010\projects\bland\bland\program.cpp(57): error C2065: 'myTown' : undeclared identifier
1>c:\users\fgmck_000\documents\visual studio 2010\projects\bland\bland\program.cpp(69): error C2065: 'myTown' : undeclared identifier
1>c:\users\fgmck_000\documents\visual studio 2010\projects\bland\bland\program.cpp(69): error C2228: left of '.setPopulation' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\fgmck_000\documents\visual studio 2010\projects\bland\bland\program.cpp(77): error C2065: 'myTown' : undeclared identifier
1>c:\users\fgmck_000\documents\visual studio 2010\projects\bland\bland\program.cpp(77): error C2228: left of '.setBirths' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\fgmck_000\documents\visual studio 2010\projects\bland\bland\program.cpp(85): error C2065: 'myTown' : undeclared identifier
1>c:\users\fgmck_000\documents\visual studio 2010\projects\bland\bland\program.cpp(85): error C2228: left of '.setDeaths' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\fgmck_000\documents\visual studio 2010\projects\bland\bland\program.cpp(90): error C2065: 'myTown' : undeclared identifier
1>c:\users\fgmck_000\documents\visual studio 2010\projects\bland\bland\program.cpp(90): error C2228: left of '.getPopulation' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\fgmck_000\documents\visual studio 2010\projects\bland\bland\program.cpp(91): error C2065: 'myTown' : undeclared identifier
1>c:\users\fgmck_000\documents\visual studio 2010\projects\bland\bland\program.cpp(91): error C2228: left of '.getBirthRate' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\fgmck_000\documents\visual studio 2010\projects\bland\bland\program.cpp(92): error C2065: 'myTown' : undeclared identifier
1>c:\users\fgmck_000\documents\visual studio 2010\projects\bland\bland\program.cpp(92): error C2228: left of '.getDeathRate' must have class/struct/union
1> type is ''unknown-type''
The changes work fine for a standard compiler:
http://ideone.com/L5y8fl

VS2010 should be fine, but how exactly are you compiling it?
Last edited on
Topic archived. No new replies allowed.