Hello. I am stuck on an assignment. Im not looking for the direct answer, more of a guide into the right direction to resolve the issue. I have to take user input of floating point numbers into an array until either 100 numbers have been reached or the user types -999 and then sort the array. i have been able to get to that point but the trouble i am having is not storing the -999 number as that is supposed to just terminate the program. I have tried to put the portion of the code that stores the userInput into the array inside of the If statement but then I get a weird negative number in the 0 index of the array
Code:
#include <stdio.h>
float bubble_sort(float list[], int n) {
float c, t;
int d;
for (c = 0; c < (n - 1); c++)
{
for (d = 0; d < n - c - 1; d++)
{
if (list[d] > list[d + 1])
{
/* Swapping */
t = list[d];
list[d] = list[d + 1];
list[d + 1] = t;
}
}
}
}
int main()
{
float userInput = 0.0f;
float inputArray[100];
int i = 0;
while (i < 100)
{
if (userInput != -999)
{
scanf_s("%f", &userInput);
}
inputArray[i] = userInput;
i++;
}
bubble_sort(inputArray, i);
printf("%f %f %f", inputArray[0], inputArray[1], inputArray[2]);
return 0;
}