NEED HELP!arrays and pointer error

I'm trying to get this to return the minimum
error:subscript array or pointer type

int minimum(const int* values, size_t numValues)
{
int min = numValues[0];
int count;
for(count = 0; count < numValues[count]; count++)
{
if(numValues[count] < min)
min = numValues[count];
}
return min;
}
Last edited on
you're trying to access a single size_t object as if it was an array. I'm guessing values is a pointer to an array and you meant to write values[count] not numValues[count]
thanks that worked but now it is showing up as an error when i try and run it here is my code:
#include <iostream>

using namespace std;


int minimum(const int* values, size_t numValues)
{
int min = values[0];
int count;
for(count = 0; count < values[count]; count++)
{
if(values[count] < min)
min = values[count];
}
return min;
}



//int maximum(const int* values, size_t numValues);


int main()
{
const size_t maxValues = 10;
int values[maxValues];
int count;

cout << " Enter up to 10 integers(-1 to stop): ";
for( count=0 ; count<maxValues ; count++ )
{
cin>> values[count];
if (values[count] == -1)
break;

}
cout<< " the number you entered were:" << endl;
for( count=0 ; count<maxValues ; count++ )
{
if (values[count] == -1)\
break;
cout << values[count]<< " "<<endl;
}

cout << " the minimum value is:" << minimum <<endl;
cout << " the maximum value is:" << endl;
return 0;



}
Last edited on
what does 0041123A mean???
Looks like a memory location.
the for loop within your min function looks like this for(count = 0; count < values[count]; count++) that doesn't stop when count reaches numValues, it checks count against values[count], the for loop should look like this

for(count = 0; count < numValues; count++)
Topic archived. No new replies allowed.