if (sale->taxStatus[i] = "y") // line 44
yields error:
y.cpp:44:12: error: request for member taxStatus in sale, which is of non-class type Sale*
My struct:
struct Sale {
int quantity[MAX_SALES];
float unitPrice[MAX_SALES];
char taxStatus[MAX_SALES]; // MAX_SALES = 10
};
the full function:
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;
}
As @jweyrich and @AustinPhillips also pointed out that you need double equal sign ( == ) and chars are compared in single quotes.
single equal sign ( = ) is used to assign value.
e.g.
s = 5;double equal sign ( == ) is used to check equality of two or more than two values.
e.g.
if( s == d && d== e && e == f && f == b ) { };equal sign with exclamation mark ( != ) is used to check inequality of two or more than two values.
e.g.
if( s != d && d != e && e != f && f != b ) { };