我不知道爲什麼這段代碼不工作,任何幫助,將不勝感激。不管我做什麼,我仍然得到同樣的錯誤。我知道需要通過更多的參數,但我不明白我可以添加什麼。功能錯誤的參數太少? (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;
}
你寫這個代碼? – Andrew 2013-04-28 17:03:27
請不要不必要地創造難題。你需要說明哪一行代碼會產生錯誤。扣留有用的信息只會浪費每個人的時間。另外,你是否認爲問題是函數的參數太少? – 2013-04-28 17:06:17