if (sale->taxStatus[i] = "y") // line 44
收率錯誤:比較C++炭結構爲ASCII值產生錯誤
y.cpp:44:12: error: request for member taxStatus in sale, which is of non-class type Sale*
我的結構:
struct Sale {
int quantity[MAX_SALES];
float unitPrice[MAX_SALES];
char taxStatus[MAX_SALES]; // MAX_SALES = 10
};
全功能:
void total(struct Sale sale[], int sales) {
int i = 0;
float subTotal, hst, total = 0;
for (i = 0; i < sales; i++) {
subTotal = subTotal + (sale->quantity[i] * sale->unitPrice[i]);
if (sale->taxStatus[i] = "y")
{
hst = hst + ((sale->quantity[i] * sale->unitPrice[i]) * 0.13);
}
}
cout << "\n" << "Subtotal : " << subTotal << endl;
cout << "HST (13%) : " << hst;
}
在第44行中使用'=='作爲等式,'='作爲賦值。 –
與''y''而不是''y' 。雙引號用於字符串文字。字符是單引號的。 – jweyrich
啊,我認爲這是相反的。現在我得到這個錯誤:'ISO C++禁止指針和整數之間的比較'行44:29 – eveo