#include<iostream>
usingnamespace std;
void sort(int arr[]);//function to sort array
int main()
{
int arr[3];//array used to store the 4 values
//gets and stores array values
cout << "Enter 4 numbers \nThe first number :";
cin >> arr[0];
cout << endl << "The second number : ";
cin >> arr[1];
cout << endl << "The third number : ";
cin >> arr[2];
cout << endl << "The forth number : ";
cin >> arr[3];
sort(arr);
cout << "Max equals : " << arr[3];
}
void sort(int arr[])
{
int num = 3;
for (int i = 0; i < num; ++i)//for loop used to sort the array into numeric order
{
for (int j = 0; j < num - i - 1; ++j)
if (arr[j] > arr[j + 1])
{
int temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
oh man thanks guys I just started learning about arrays and this was driving me nuts it works now. I got confused thinking I needed to use 3 because arrays use 0 instead of 1 as the starting array number.