Using floats, I'm trying to have a user fill an array. Then have a user input an element they want to know the location of.
It works fine for decimal inputs but when I input a negative number it doesnt find it in the array
Code:
#include<stdio.h>
int main() {
int n, i;
float array[100], elem;
printf("Enter the number of elements in an array:\n");
scanf("%d", &n);
printf("Enter the values of each element:\n");
for(i=0;i<n;i++){
scanf("%f", &array[i]);
}
printf("\n");
printf("which element are you looking for?\n");
scanf("%f", &elem);
i=0;
while(i<n && elem != array[i]){
i++;
}
if(i<elem)
printf("Your element is located at element: %d", i);
else
printf("-1");
return (0);
}