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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <iostream>

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;
}
closed account (2b5z8vqX)
1
2
3
4
5
6
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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <iostream>
#include <iomanip>

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.