Iterate variable (newbie)
Just starting C, so I have some problems with the basics!
I have several inputs and need to identify the largest inputted number.
I am told by my teacher to use a loop.
so far I have this
Code:
float n1, n2;
while (n1 >= 0)
{
printf("Enter any number: \n");
scanf("%f", &n1);
printf("Enter any number: \n");
scanf("%f", &n2);
/* Reads two numbers */
if (n1 > n2)
max = n1;
else
max = n2;
/* Compare the two numbers, keep the higher number. */
}
printf("Largest number is: %f", max);
I want the program to stop running and outputting the highest number if 0 or a negative number is inputted.
I see the potential bug with n1 >= 0 with that n2 can be typed in as a break parameter.
Should I possibly pull the n1, n2 outside the while loop and then keep the 'max' inside the loop ?