samaank
March 2nd, 2006, 04:36 AM
hi, i'm having problems getting my code to work, i'm very new to C++, what i want this code to do is to display the location of the largest value of the array.
#include <algorithm> // for min_element/max_element
#include <iostream> // for cout
using namespace std;
int main()
{
cout <<"witness the awesome power of the LARGEST VALUE IN ARRAY FINDER !!!\n\n";
int array[] = {5,6,3,230,3,4,6,110};
unsigned const num_elements=sizeof(array)/sizeof(int);
int largest = *max_element(array,array+num_elements);
int bigpos;
bigpos = array[&largest];
cout <<"It's position in the array is "<< bigpos<<"\n";
cout <<"Largest value in array: "<<largest;
cin.get();
cin.get();
return 0;
}
it should display 3 as the answer but it wont even compile.
can someone help me fix this problem ?
#include <algorithm> // for min_element/max_element
#include <iostream> // for cout
using namespace std;
int main()
{
cout <<"witness the awesome power of the LARGEST VALUE IN ARRAY FINDER !!!\n\n";
int array[] = {5,6,3,230,3,4,6,110};
unsigned const num_elements=sizeof(array)/sizeof(int);
int largest = *max_element(array,array+num_elements);
int bigpos;
bigpos = array[&largest];
cout <<"It's position in the array is "<< bigpos<<"\n";
cout <<"Largest value in array: "<<largest;
cin.get();
cin.get();
return 0;
}
it should display 3 as the answer but it wont even compile.
can someone help me fix this problem ?