I don't want to initialize n1 since it can be any positive number and I risk initializing it higher than the inputted number.
Code:
int main(void) {
float n1, max=0;
printf("Enter any number: ");
fflush(stdout);
scanf("%f", &n1);
/* Putting the input outside the loop, I make sure n1 is never
* a random number and will always continue to the while loop*/
while (n1 > 0)
{
printf("Enter any number: ");
fflush(stdout); /* Compiler won't stop to print line */
scanf("%f", &n1);
if (n1 > max)
max = n1;
}
printf("Largest number is: %f", max);
return EXIT_SUCCESS;
I put another line outside the loop, but I think it looks a bit untidy... is there any way of simplifying this, so I don't have repeating-lines?
edit: Oddly, it reads the decimal numbers as the highest numbers, if I type number like 25 and 0.25 it will read out the 0.25 as the higher number. If I only use integers, it works as intended?