2013-04-28 200 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);