This is an adaption of a Chapter 7 review question from Stephen Prata's C++ Primer Plus. I want to output the maximum value in the array as calculated in the function x but am getting an error on the line:
cout << x (boy[],3);
Any ideas?
#include <iostream>
usingnamespace std;
int x(constint b[], int size);
int main()
{
int dog[3] = { 12, 15, 22 };
cout << x (dog[],3);
return 0;
}
int x(constint b[], int size)
{
int max;
if (size < 1)
{
cout << "Invalid array size of " << size << endl;
cout << "Returning a value of 0\n";
return 0;
}
else
{
max = b[0];
for (int i = 1; i < size; i++)
if (b[i] > max)
max = b[i];
return max;
}
}
What was the exact compiler error message? The purpose of the message is to tell what the compiler does not understand. Learning to understand those messages is both important and useful. Alas, some messages are cryptic.