Trying to tackle the Pancake Glutton exercise and been looking at trying to sort() an Array and failing somewhat at it.
I'm having problems with the sort() function. I understand the logic of giving it a place to start and a place to finish and then a method to sort by, but none of the 4 methods I've tried are accepted. Would someone be able to shed some light on this for me please? Thanks!
The error I'm most miffed by is: no operator "[]" matches these operands. operand types are: PanPerPerson [int]
I learnt using Python and I'm guessing there's a problem with the circumstances you can use square brackets to say which element of a Stuct/Array to look at?
The only problem I see is on line 39, where you are trying to sort from arPancakes[0] to arPancakes[10]...however using the array subscript in sort is incorrect, because that returns the item itself. Change it one of the other sort usages (like .begin()/.end()) and it should work fine.
int pancakesEaten[10];
for (int i = 0; i < 10; i++)
{
cout << "How many Pancakes did " << i +1 << " eat: ";
cin >> pancakesEaten[i];
}
int smallest = pancakesEaten[0];
int largest = pancakesEaten[0];
for (int i = 0; i < 10; i++)
{
if (pancakesEaten[i] < smallest)
{
smallest = pancakesEaten[i];
}
if (pancakesEaten[i] > largest)
{
largest = pancakesEaten[i];
}
}
cout << endl << "Largest amount of pancakes eaten is: " << largest << endl;
cout << "Smallest amount of pancakes eaten is: " << smallest << endl;
There are errors on 37,38,39 & 40. I've tried using a couple of combinations of the begin/end but both are giving me errors.
The first I tried using the .begin() and .end() method but the arPancakes.nNumberOfPancakes.begin() gives me an 'expression must have class type' error, and the arPancakes.end() gives me a 'PanPerPerson has no member "end" '. I know that the begin and end should be the same, but for demonstration purposes I'm showing that I've tried two different ways of using .begin() and .end()
The second I tried gives me an error 'no operator "[]" matches these operands. operand types are: PanPerPerson [int]'