2013-04-28 64 views
-8

我不知道为什么这段代码不工作,任何帮助,将不胜感激。不管我做什么,我仍然得到同样的错误。我知道需要通过更多的参数,但我不明白我可以添加什么。功能错误的参数太少? (C++)

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

你写这个代码? – Andrew 2013-04-28 17:03:27

+2

请不要不必要地创造难题。你需要说明哪一行代码会产生错误。扣留有用的信息只会浪费每个人的时间。另外,你是否认为问题是函数的参数太少? – 2013-04-28 17:06:17

回答

1

函数参数中缺少findHighest()函数。

功能减速void findHighest(double sale[]);

您没有提供参数double sale[]

因此findHighest()更换线[系统之前行( “暂停”)语句]与findHighest(sale)

+0

谢谢你明确定义错误在哪里。 – jklazzara 2013-04-28 17:11:48

+0

欢迎。:) :)另外,如果答案对你有用,那么请不要忘记勾选(接受),以便它可以帮助未来的访问者在Stack溢出社区:) – 2013-04-28 17:14:27

1

你的函数调用:

findHighest(); 

你的函数声明:

void findHighest(double sale[]); 

看到这些确实的“参数太少运作”错误有意义吗?这个错误很自我解释..是的?

0
void findHighest(double sale[]); 

和你被

findHighest(); 

称之为这是错误的。

传递双值的数组,以findHighest

findHighest(sale);