Member Avatar for Nick6425fl

I have 1 line in this code that I can't get to compile. I'm new to C++ and begging for some help...any advise would be appreciated.

#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;
}

Which line? You can either use C++ code tags:

[cose=cplusplus] // paste code here

[/code]

which add line numbers, and you can reference the line number, or you can highlight the relevant line in red. Give the compiler error too please.

Member Avatar for Nick6425fl

Thank you....that was my first post.

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



const int NAME_SIZE = 26;


double getSales (char []);
void findHighest(double, double, double, double);

int main()
{

double input_div(string);
   double salesNE,  
          salesSE,  
          salesNW,  
          salesSW; 

   
   salesNE = getSales("Northeast"); 
   salesSE = getSales("Southeast"); 
   salesNW = getSales("Northwest"); 
   salesSW = getSales("Southwest"); 


   findHighest( salesNE, salesSE, salesNW, salesSW);
  

cout << "Enter the quarterly sales for the Northeast division: ";
cin >> salesNE;

while (salesNE <=0)
{
cout << "Sales must be a non-negative number.";
cout << "Enter the quarterly sales for the Northeast division: ";
cin >> salesNE;

}
cout << "Enter the quarterly sales for the Southeast division: ";
cin >> salesSE;
while (salesSE <=0)
{
cout << "Sales must be a non-negative number.";
cout << "Enter the quarterly sales for the Southeast division: ";
cin >> salesSE;
}

cout << "Enter the quarterly sales for the Northwest division: ";
cin >> salesNW;
while (salesNW <=0)
{
cout << "Sales must be a non-negative number.";
cout << "Enter the quarterly sales for the Northwest division: ";
cin >> salesNW;
}
cout << "Enter the quarterly sales for the Southwest division: ";
cin >> salesSW;
while (salesSW <=0)
{
cout << "Sales must be a non-negative number.";
cout << "Enter the quarterly sales for the Southwest division: ";
cin >> salesSW;

}
}
void findHighest(double salesNE, double salesSE, double salesNW, double salesSW)
{
  string highest, name;
  highest = "salesNE";
  name = "Northeast";

	if(salesSE > highest)
      {
         highest = "salesSE";
	     name = "Southeast";
      }

	if(salesNW > highest)
      {
		highest = "salesNW";
		name = "Northwest";
      }

	if(salesSW > highest)
      {
		highest = "salesSW";
		name = "Southwest";
      }

	cout << "The highest division is " << name << " with $" << highest << endl;
}

 return 0;
}

Okay, which line number is the problem on though? Actually, this is the same as your other thread, right? I just commented there. You should mark this one "solved" since you have two threads on the same topic.

I have 1 line in this code that I can't get to compile. I'm new to C++ and begging for some help...any advise would be appreciated.

#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;
}

hi,

your mistake is here,

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); //---> do not include datatypes while calling any function okay.
//-----------------------------------------------------------------------//
startPop = population (birthRate, deathRate, numYears, n); //-----> this is correct calling.
//-----------------------------------------------------------------------//


cout << "For year " << i+1 << " the population is " << startPop << endl ;
}

}

do not include data types while calling any function okay. Datatypes are part function declaration.

--
Regards,
Asif

Member Avatar for Nick6425fl

Thank you for the reply, but Vernon already helped me out on a previous post in this thread.

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.