Ordered list using binary search

So, i created an ordered array of float.
here is the code.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41

//from main
	for(int i = 0; i < LIM; i++)
	{
		
		cout << ">> ";
		cin >> num;
		input(orderedList, num, i); 
		//ordered list is an array of float
	}
	
//function
void input(float list[], float item, int iter)
{
	int first = 0;
	int last =  iter; //serves as the length of the array
	unsigned int mid;
	bool found = false;

	if(iter == 0)
	{
		list[0] = item;
		return;
	}
	else
		while(first <= last )
		{
			mid = (first + last) / 2;
			if(list[mid] > item) //**error
				last = mid - 1;
			else
				first = mid + 1;
		}
	if(list[mid] <= item)
		mid++;
	if(list[mid] > item)
		for(int i = iter; i > mid; i--) // moves every element  to one space
			list[i] = list[i-1];
		
	list[mid] = item;
}

the code is fine is my input is: 64 32 1 8 12
and if my input is: 32 64 1 8 12 it goes wrong
I already isolated my problem, which is if my first input is less than the second input it will be s***, otherwise it's okay.
Can someone help me fix my algorithm, i've been thinking of a fix for hours.

NOTE: The requirement is using binary search populate the ordered array.
Topic archived. No new replies allowed.