A friend of mine is trying to learn c (on her own, with a book) and sometimes she asks for help.
She just showed me something I can't answer; I'm ashamed but I studied C in college and then moved to php. I'm really stuck so I would like to know why we can't get three inputs. Here's partial code:
#include <stdio.h>
int main()
{
int num1;
int num2;
char x;
printf("Enter a number:\n");
scanf("%d\n",&num1);
printf("Enter another number:\n");
scanf("%d\n",&num2);
printf("Choose an operation sign:\n");
scanf("%c\n",&x);
...
Like this it asks for the first input two times, like this:
Enter a number:
1
2
Enter another number:
3
Choose an operation sign:
-
If I remove the \n
it skips the last scanf
.
Can you help me understand why?