I'm having a problem with my program skipping over the 2nd scanf function. I am new to programming and am not sure why this is.
when I run this I do not get prompted for a 2nd input, it just skips right over it.
printf("Enter a simple arithmetic expression.\n");
success = scanf("%d%c%d\n",&m,&op,&n);
ans = m + n;
printf("What is the answer to %d%c%d?\n",m,op,n);
scanf(" %d\n" , &input);
if(ans == input)
printf("No, the correct answer is %d\n",ans);
ans = m - n;
ans = m * n;
ans = m / n;
ans = m % n;
Very common complaint. When you hit enter, the input stream gets a newline put into it. That newline char is NOT included in your variable, but it's left in the buffer. When the next scanf() is reached, the buffer is read. If a char will foul things up at that time, then it will be "skipped".
You can fix it by adding a blank space before the first % in the second scanf(), or by putting a getchar() line of code, after the first scanf(). that will fix the problem.
Since you've already tried the first method, I strongly suggest the latter, ( the getchar() ), and put it after each of the two scanf()'s, just to be thorough.
Thank you very much! The getchar()worked perfectly.