I'm new to C programming, and I am having trouble with the following code.
#include <stdio.h>
int main(void)
{
int input_number;
int largest_number = 0;
char reply;
printf("Hello world\n");
printf("This is a simple program, that will output the largest number entered\n");
printf("Please enter a number");
while (reply != 'N')
{ // Start of WHILE loop
printf("Please enter a number");
scanf("%d",&input_number);
if (input_number > largest_number)
largest_number = input_number;
printf("\nDo you wish to enter another number? Y/N\n");
scanf("%c",&reply); // Problem with this line
} // End of WHILE loop
printf("%d",largest_number);
getch();
The problem is this: When the user enters a number, the program outputs 'Do you wish to enter another number? Y/N'. The program does not wait for an answer though, and outputs 'Please enter a number'. The loop does stop if you enter 'N' instead of a number.
How can I get the program to wait before outputting 'Please enter a number' and exit the loop if the reply to 'Do you wish to enter another number?' is 'N'?