Member Avatar for Nick6425fl

I'm a newbie at posting code so I'm sorry if I make any mistakes. The 26 line won't let me compile and I don't understand why. can anyone help me???

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

double population(double pop, double birthRate, double deathRate);
 void printPopulations(
  double startPop, double birthRate, double deathRate, int numYears);


	double population(double pop, double birthRate, double deathRate)
    {

double n = 0;

n = pop + (birthRate*pop) - (deathRate*pop);

return n;

}

void printPopulations(double startPop, double birthRate, double deathRate, int numYears)
{

for ( int i = 0 ; i < numYears ; i++ )
{
startPop = population (double birthRate, double deathRate, numYears, double n);
cout << "For year " << i+1 << " the population is " << startPop << endl ;
}

}



int main()
{
        double startPop,          
              birthRate,        
              deathRate;       
        int   numYears;         

        
        cout << "This program calculates population change.\n";
        cout << "Enter the starting population size: ";
        cin  >> startPop;
        while (startPop < 2.0)
        {
                cout << "Starting population must be 2 or more.  Please re-enter: ";
                cin  >> startPop; 
        }

        
        cout << "Enter the annual birth rate (as % of current population): ";
        cin  >> birthRate;
        while (birthRate < 0)
        {
                cout << "Birth rate percent cannot be negative.  Please re-enter: ";
                cin  >> birthRate;
        }

        birthRate = birthRate / 100;     

        cout << "Enter the annual death rate (as % of current population): ";
        cin  >> deathRate;
        while (deathRate < 0)
        {
                cout << "Death rate percent cannot be negative.  Please re-enter: ";
                cin  >> deathRate;
        }

        deathRate = deathRate / 100;     

        cout << "For how many years do you wish to view population changes? ";
        cin  >> numYears;
        while (numYears < 1)
        {
                cout << "Years must be one or more. Please re-enter: ";
                cin  >> numYears;
        }

        printPopulations(startPop, birthRate, deathRate, numYears);
        system ("pause");
        return 0;
}

Recommended Answers

All 4 Replies

In line 26 this:

population (double birthRate, double deathRate, numYears, double n);

is a function declaration, not a function call. Function calls don't list argument types, just argument names or argument values.

Member Avatar for Nick6425fl

I'm still learning about all of this...I'm sure when I look back at this post in a couple of months I'll laugh. Thanks for the reply, but what do you think that line should exactly be to make that code work?

I'm still learning about all of this...I'm sure when I look back at this post in a couple of months I'll laugh. Thanks for the reply, but what do you think that line should exactly be to make that code work?

If you format/indent your code, it'll be much easier to follow. To answer your question, I can recommend something that will be a proper function call, but it doesn't make any sense here. I think you need to take a step back and decide what you are trying to do.

This is a function call:

startPop = population (startPop, birthRate, deathRate);

I doubt that is what you want, but it is a legal function call.

Member Avatar for Nick6425fl

If you format/indent your code, it'll be much easier to follow. To answer your question, I can recommend something that will be a proper function call, but it doesn't make any sense here. I think you need to take a step back and decide what you are trying to do.

This is a function call:

startPop = population (startPop, birthRate, deathRate);

I doubt that is what you want, but it is a legal function call.

That fixed it! Next time I post I'll indent to make it easier to read. Thank you again Vernon.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.