我無法編譯,這個程序給我錯誤。我已經花了3天的時間。我不明白這些編譯錯誤
C:\南澳\ COS1511 \ TEST.CPP
[警告在函數'漂浮calcAllowedPerChild(浮點)':
錯誤C:\南澳\ COS1511 \ TEST.CPP:26個
無效操作數類型float()(float)
和const float
爲二進制operator<
#include <iostream>
using namespace std;
const float maxPerUnit = 20000.00;
//minPerChild include a standard gift consisting of a bath towel and facecloft
const float minPerChild = 100.00;
const float maxPerChild = 180.00;
//Depending on the amount the child may also get one or more of the fallowing:
const float TOOTHBRUSH = 29.95;
const float HIGHLIGHTERS = 25.99;
const float CRAYONS = 17.95;
const float NOTEBOOK = 12.95;
const float PEN = 9.99;
//You must add the function calcAllowebPerchild() here
float calcAllowedPerChild (float nrChildren)
{
float allowedPerChild = maxPerUnit/nrChildren;
if (allowedPerChild > maxPerChild || calcAllowedPerChild < minPerChild)
return maxPerChild;
else
return minPerChild;
}
int main()
{
float amtGift; //Allowed amount per child
float amtSpendPerChild = 0.00; //actual amount spend per child
float totalSpend = 0.00; //total spend for one orphanage
float totalAll = 0.00; //total spend for all 4 orphanages
int nrChildren; //number of chldren per orphanage
cout << "Enter the number of children: " << endl;
cin >> nrChildren;
amtGift = calcAllowedPerChild(nrChildren);
cout.setf(ios::fixed);
cout.precision(2);
cout << endl << " Allowable amount per child :R" << amtGift;
cout << endl << endl;
return 0;
}
需要'家庭作業'標籤? – 2011-03-23 22:23:49
這條線上有一個分號'float calcAllowedPerChild(float nrChildren);'你可能不需要。 – ChrisF 2011-03-23 22:25:27