我正在编写一个使用不同.cpp文件中的函数的简单程序.我的所有原型都包含在头文件中.我将一些函数传递给其他函数,我不确定我是否正确执行.我得到的错误是"'functionname'不能用作函数".它说不能使用的growthRate功能是功能和estimatedPopulation功能.数据通过输入函数(我认为它正在工作)进入.
谢谢!
头文件:
#ifndef header_h
#define header_h
#include <iostream>
#include <iomanip>
#include <cstdlib>
using namespace std;
//prototypes
void extern input(int&, float&, float&, int&);
float extern growthRate (float, float);
int extern estimatedPopulation (int, float);
void extern output (int);
void extern myLabel(const char *, const char *);
#endif
Run Code Online (Sandbox Code Playgroud)
growthRate函数:
#include "header.h"
float growthRate (float birthRate, float deathRate, float growthrt)
{
growthrt = ((birthRate) - (deathRate))
return growthrt;
}
Run Code Online (Sandbox Code Playgroud)
估计人口功能:
#include "header.h"
int estimatedPopulation (int currentPopulation, float growthrt)
{
return ((currentPopulation) + (currentPopulation) * (growthrt / 100);
}
Run Code Online (Sandbox Code Playgroud)
主要:
#include "header.h"
int main ()
{
float birthRate, deathRate, growthRate;
char response;
int currentPopulation, years, estimatedPopulation;
do //main loop
{
input (currentPopulation, birthRate, deathRate, years);
growthRate (birthRate, deathRate, growthrt);
estimatedPopulation (currentPopulation, growthrt);
output (estimatedPopulation (currentPopulation, growthrt));
cout << "\n Would you like another population estimation? (y,n) ";
cin >> response;
}
while (response == 'Y' || response == 'y');
myLabel ("5-19", "12/09/2010");
system ("Pause");
return 0;
}
Run Code Online (Sandbox Code Playgroud)