I'm not finished with my program yet, but i've run into a few problems. The first main problem i see is that i seem to be doing something wrong to display the array that the user enters. It only shows one value, and it displays it twice. I cant check my other functions because that one doesn't work properly. Can anyone tell me what im doing wrong?
I also get 2 errors saying:
(37) : error C2065: 'max' : undeclared identifier
(40) : error C2065: 'min' : undeclared identifier
my code is below.
thx in advance for any help.
#include<iostream.h>
int get_array(int array[], int& size);
int display_array(int array[], int& size);
void reverse_array(int array[], int size);
int find_max(int array[], int size);
int find_min(int array[], int size);
void sort_array(int array[], int size);
int smallest_spread();
int largest_spread();
int positive_negative();
int index_of_smallest(const int array[], int start_index, int number_used);
void swap_values(int& v1, int& v2);
void main()
{
int size;
int original_array[20];
int positive_array[20];
int negative_array[20];
get_array(original_array, size);
cout << "\nOriginal";
cout << display_array(original_array, size);
reverse_array(original_array, size);
cout << "\nReversed";
cout << display_array(original_array, size);
find_max(original_array, size);
cout << "\nMaximum value = "<< max;
find_min(original_array, size);
cout << "\nMinimum value= " << min;
sort_array(original_array, size);
cout << "\nSorted";
cout << display_array(original_array, size);
}
int get_array(int array[], int& size)
{
cout << "Enter the array size: ";
cin >> size;
if(size > 20)
cout << "Invalid size entered.";
else
for(int i=0; i < size; i++)
{
cout << "Enter element #" << i+1 << ": ";
cin >> array[i];
}
return size;
}
int display_array(int array[], int& size)
{
for(int i=0; i < size; i++)
{
cout << " array: " << array[i];
return array[i];
while(i<size)
cout<< ", ";
}
return 0;
}
void reverse_array(int array[], int size)
{
int temp;
int j = size-1;
for(int i = 0; i < size/2; i++, j--)
{
temp = array[i];
array[i] = array[j];
array[j] = temp;
}
}
int find_max(int array[], int size)
{
int max=array[0];
for(int i=1; i < size; i++);
{
if(array[i]> max)
max = array[i];
}
return max;
}
int find_min(int array[], int size)
{
int min = array[0];
for(int i=1; i < size; i++)
{
if(array[i] < min)
min = array[i];
}
return min;
}
void sort_array(int array[], int size)
{
int index_of_next_smallest;
for(int i = 0; i < size-1; i++)
{
index_of_next_smallest= index_of_smallest(array, i, size);
swap_values(array[i], array[index_of_next_smallest]);
}
}
void swap_values(int& v1, int& v2)
{
int temp;
temp = v1;
v1 = v2;
v2 = temp;
}
int index_of_smallest(const int array[], int start_index, int number_used)
{
int min = array[start_index],
index_of_min = start_index;
for(int i = start_index + 1; i < number_used; i++)
if(array[i] < min)
{
min = array[i];
index_of_min = i;
}
return index_of_min;
}