Code:
printf("enter a number hit return then repeat.\n");
Actually, all the user has to do is put some sort of whitespace between the numbers. A newline will do, but so would a space or a tab or anything that isspace() returns true for.
when you pass in arguments to scanf, they should be a memory address.
What you were doing was passing the values of the variables a and b (which are uninitialized, [somewhat] random values). scanf() needs to know where the variables are located in memory so it can put the value the user entered into it.
scanf() returns the number of fields successfully read in. So if you use scanf("%d%d", &a, &b), a good way to see if it worked would be to use
Code:
if(scanf("%d%d", &a, &b) == 2) {
/* successfull */
}
else {
/* error */
}
scanf() might not be successfull if, say, the user entered "large" instead of a number. A good way to handle an error like that would be to flush the input buffer using code in my previous post and try again:
Code:
while(scanf("%d%d", &a, &b) != 2) {
int c;
printf("Invalid number! Please try again: ");
while((c = getchar()) != '\n' && c != EOF);
}