### Population

I can't to seem to understand why is void getRate(Population &geo); giving an error?

New types may not be defined in a return type.

 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859`` ``````#include using namespace std; struct Population { int population, birth, death; double birthRate, deathRate; } void getRate(Population &geo); void showRate (Population); int main () { Population geo; getRate(geo); showRate(geo); cout << "\n\n"; } void getRate(Population &geo) { cout << "Enter the number of births: "; cin >> geo.birth; if (geo.birth < 0) { geo.birth = 0; } cout << "\nEnter the number of deaths: "; cin >> geo.death; if (geo.death < 0) { geo.death = 0; } cout << "\nEnter the number of population: "; cin >> geo.population; if (geo.population < 2) { geo.population = 2; } geo.birthRate = geo.birth/geo.population; geo.deathRate = geo.death/geo.population; } void showRate(Population geo) { cout << "In a population of " << geo.population << ", there are " << geo.birth << " births in a rate of " << geo.birthRate << "\n and the number of deaths are " << geo.death << ", in a rate of " << geo.deathRate; }``````
 ``123456`` ``````struct Population { int population, birth, death; double birthRate, deathRate; };``````

A semicolon should be the final character in the definition of a type.
*Face palm* Sigh. Thanks. Let me check if it works.

EDIT: I had an issue with the calculations, but it works now.

 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970`` ``````#include #include using namespace std; struct Population { int population, birth, death; double birthRate, deathRate; }; void getRate(Population &geo); void showRate (Population); int main () { Population geo; getRate(geo); showRate(geo); cout << "\n\n"; system("pause"); return 0; } void getRate(Population &geo) { cout << "Enter the number of births: "; cin >> geo.birth; if (geo.birth < 0) { geo.birth = 0; } cout << "\nEnter the number of deaths: "; cin >> geo.death; if (geo.death < 0) { geo.death = 0; } cout << "\nEnter the number of population: "; cin >> geo.population; if (geo.population < 2) { geo.population = 2; } geo.birthRate = 1.00*geo.birth/geo.population; geo.deathRate = 1.00*geo.death/geo.population; } void showRate(Population geo) { cout << "\nThe population is \t\t" << geo.population << "\n"; cout << "The number of births are \t" << geo.birth << "\n"; cout << "The number of deaths are \t" << geo.death << "\n"; cout << fixed << showpoint << setprecision(2); cout << "The rate of births is \t\t" << geo.birthRate << "\n"; cout << "The rate of deaths is \t\t" << geo.deathRate << "\n"; }``````
Last edited on
Topic archived. No new replies allowed.