2014-02-26 65 views
0
void displayCost(); 
double computeArea(); 
double roundCost(); 

int main() 
{} 
void displayCost(string name, int size) 
{ 
double area = computeArea(size); 

cout << "Since a " << size << "-inch pizza covers" << area << "square inches, " 
    << name << ", then a 12 cents per square inch, the cost will be" << 12*area << " - which rounds to" 
    << roundCost(); 
} 

double computeArea(int size) 
{ 
double radius = size/2; 
double area = pi*radius*radius; 
return area; 
} 

double roundCost(double price) 
{ 
double roundedCost = ceil(price*100)/100; 
return roundedCost; 
} 

它發生在double area = computeArea(size);的行上。我不明白爲什麼當我清楚地表示我沒有通過爭論時。編譯錯誤:函數不帶1個參數

+4

您聲明爲不帶參數:'double computeArea();' –

回答

0

你搞亂了你的轉發聲明,他們也必須反映你函數的參數類型。

void displayCost(string, int); 
double computeArea(int); 
double roundCost(double); 
5
double computeArea(); 
double area = computeArea(size); 
double computeArea(int size) { 

One of these things is not like the others, ..

你需要修復您的原型(第一個),以符合實際的功能:

double computeArea(int); 

,當然,同上,用於其他的原型爲好。

+0

非常感謝!我不知道你需要在原型中陳述論證的類型。 –

+0

@Jesse,在C中,你沒有。將它們留在那裏意味着有任何類型的_indeterminate_數量的參數。在C++中,將它們放在外面與使用'void'相同 - 完全有_zero_參數。 – paxdiablo

0

C++與C的不同之處在於函數的前向聲明必須指定參數的數量和類型。而用C

double computeArea(); 

意味着,有一些所謂的computeArea函數返回double,在C++中,它是一樣的

double computeArea(void); 

也就是說,它指定computeArea帶任何參數。

大概不同的是,C++允許函數被重載,而C不能。

0

你已經聲明瞭computeArea在原型中佔據了零個參數(主要部分)。事實上,你已經把它定義爲在下面加倍下來就是重點。在主內部,你用一個參數來調用它,根據原型,它是錯誤的。