I'm a total n00b to programming in general, so forgive me if this is a bad question, but I've been searching all over the place and can't quite find an answer for my particular problem.
I want to develop good coding habits as I'm learning, so I'm concerned about this very small problem I've run into. I have a simple program that reads 2 numbers and prints them on the screen. I'm using the getchar() function to stop the output from closing, instead of the system(pause), which I understand is the right way. However, it seems that it doesn't work unless I put 2 getchar()'s at the end of the program, and I can't quite figure out why. Here's what I've got:
If I only use 1 getchar() then the program closes after entering the numbers. What am I missing here?
int a, b;
printf("Please enter a number: ");
printf("\n\nPlease enter another number: ");
printf("\n\nHello, World! You entered %d and %d!", a, b);