I have to make a program that takes 4 inputs and outputs the 2 largest inputs. So I wrote this code,
#include <iostream>
using namespace std;
void largest_two ( int input[4], int output[2] )
{
bool restart;
int i;
int temp;
do
{
restart = false;
for ( i = 0; i < 3; i++ )
{
if ( input[i] < input[i+1] )
{
temp = input[i];
input[i] = input[i+1];
input[i+1] = temp;
restart = true;
}
}
}while ( restart = true );
output[0] = input[0];
output[1] = input[1];
}
int main()
{
int input[4];
int output[2];
cout << "Please enter four numbers:" << endl;
cin >> input[0];
cin >> input[1];
cin >> input[2];
cin >> input[3];
largest_two ( input, output );
cout << "The largest two of the numbers you entered are " << output[0] << "and " << output[1];
cin.ignore();
cin.get();
}
and compiled it. When I ran it, it allowed my to input the 4 numbers, but at the function call, it froze up. I figure its a problem with my bubblesort, since I always screw that up, but I didn't see anything wrong with it. Can someone point out my error?