Why is my [i] counter giving me this error?

I am trying to calculate the total cost per item (quantity * price) but my counter variable is giving me this error: Any help would be greatly appreciated! I used [i] like this earlier in my program so I am a bit confused.

"No operator "[]" matches these operands
operand types are Invoice[int]

1
2
3
4
5
6
7
void getCost(Invoice invoices, const int NUM_ITEMS)
{
	for (int i = 0; i < NUM_ITEMS; i++)
	{
		double cost = invoices[i].getPrice() * invoices[i].getQuan();
	}
}
Last edited on
It depends on what Invoice is exactly. Assuming that it's just a class or struct then maybe you meant to pass an array and forgot the asterisk:
 
void getCost(Invoice *invoices, int size)

Perfect answer, thank you!
Topic archived. No new replies allowed.