I'm trying to create a function that asks the user for a value, which then will be stored as the max or min value entered, or if the user inputs a number < 0, it will exit the dataentry() function, else it will keep asking the user for input.
#include <stdio.h>
#include <string.h>
void dataentry();
int count = 0;
float max, min, mean, old, new;
float data;
char Old[10],Data[10],choice[25];
int main(void)
{
dataentry();
}
void dataentry()
{
printf(" |Enter Wind Speed Value:\n");
printf("**|Enter -1 to exit data entry mode|**\n");
fgets(Old, sizeof(Old), stdin);
sscanf(Old, "%f",&old);
max = old;
min = old;
data = 1;
count = 1;
printf("max=%f, min=%f, data=%f, count=%d.", max, min, data, count);
for (count == 1;data >= 0; count++)
{
printf("\nEnter data value: ");
//fgets(Data, sizeof(Data), stdin); // I commented this out because I got a coredump error with it in
sscanf(Data,"%f", &data);
if (data >= max)
{
max = data;
}
else if (data <= min && data > 0)
{
min = data;
}
}
}
After the program prompts you the first time to enter data, before it reaches the for loop, it works and you enter your value. Then however it goes into an infinite loop printing "Enter data value: " over and over. I used the printf statement that prints out the max, min, data, and count values so I could check that they are being stored and they are, but when the function gets to the for loop it no longer does what I'm trying to do. Thank you in advance, this function is part of a larger program I'm writing but I cut all the irrelevant stuff out.