我不知道为什么这段代码不起作用,任何帮助都将不胜感激。无论我做什么,我仍然会得到同样的错误。我知道需要传递更多的参数,但我只是看不到我能添加的内容。
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
double getSales();
void findHighest(double sale[]);
int main()
{
double sales;
const int ARRAY_SIZE = 4;
double salesNE, salesSE, salesNW, salesSW;
double highest = 0;
string winner;
string names[ARRAY_SIZE] = {"Northeast", "Southeast", "Northwest", "Southwest"};
double sale[ARRAY_SIZE];
int counter = 0;
cout<<"Input data for the Northeast Division:"<<endl;
sale[0] = getSales();
cout<<"Input data for the Southeast Division:"<<endl;
sale[1] = getSales();
cout<<"Input data for the Northwest Division:"<<endl;
sale[2] = getSales();
cout<<"Input data for the Southwest Division:"<<endl;
sale[3] = getSales();
findHighest();
system("PAUSE");
return 0;
}
double getSales()
{
double sales;
validate:
cout<<"Enter the quaterly sales figures for this division:"<<endl;
cin>>sales;
if (sales < 0)
{
system("CLS");
cout<<"Invalid input: sales figures must be higher than $0.00"<<endl;
goto validate;
}
return sales;
}
void findHighest(double sale[])
{
const int ARRAY_SIZE = 4;
double highest = 0;
int counter = 0;
string winner;
string names[ARRAY_SIZE] = {"Northeast", "Southeast", "Northwest", "Southwest"};
while (counter < ARRAY_SIZE)
{
if (sale[counter] > highest)
{
highest = sale[counter];
winner = names[counter];
}
counter += 1;
}
cout<<"The "<<winner<<" division had the highest grossing sales at $"<<highest<<"." <<endl;
}
答案 0 :(得分:1)
您的函数调用:
findHighest();
您的职能声明:
void findHighest(double sale[]);
看到这些 “功能” 错误的参数太少有意义吗?这个错误几乎是自我解释的。是吗??
答案 1 :(得分:1)
函数参数缺失。
功能减速为void findHighest(double sale[]);
您没有提供参数double sale[]
因此用[{1}}
替换行findHighest()
[系统之前的行(“PAUSE”)语句]
答案 2 :(得分:0)
void findHighest(double sale[]);
你正在通过
来调用它 findHighest();
这是错的。
将一组double值传递给findHighest
:
findHighest(sale);