Turn your compiler warnings all the way up:
Code:
$ make dice
gcc -Wall -Wunreachable-code -ggdb3 -std=c99 -pedantic -lm -lpthread dice.c -o dice
dice.c: In function ‘main’:
dice.c:43: warning: left-hand operand of comma expression has no effect
dice.c:44: warning: left-hand operand of comma expression has no effect
dice.c:59: warning: left-hand operand of comma expression has no effect
dice.c:60: warning: left-hand operand of comma expression has no effect
dice.c:26: warning: unused variable ‘answer’
dice.c: In function ‘dice_roll’:
dice.c:138: warning: control reaches end of non-void function
Lines 43, 44, 59 and 60: That has to do with the ("%i", rand()...) lines, see below.
Line 26: remove the extraneous variable.
Line 138 (and 9): You declare dice_roll to return an integer, but you never return anything, nor do you attempt to use the return value anywhere. Simply declare it to return void: void dice_roll(int x). Make sure you change the prototype and the definition.
That's fine, continue with scanf, however, immediately after you call it, flush the input buffer, as shown in the link I provided in my post #2 above. I suggest putting that code in a function so you can reuse it. Then, when you want to wait for the user to press enter, simply call the flush_input() function and you'll be all set.
And it does. I guess I just don't understand why there is a "%i" in there, I thought you were trying to call printf or something. If not, that "%i" is totally useless, only the value of the right-most part of a comma expression is assigned to a. Since the left part doesn't even do anything (it's equivalent to something like
x; which has no effect), it's totally ignored (hence the warnings above), so you can drop it. You just need
Code:
a = rand() % (MAX_VAL - MIN_VAL + 1) + MIN_VAL;
Similarly, what std10093 was saying is that
Code:
compscore = 0 + compscore;
is completely useless. It does not change the value of compscore, or have any other side effect, so you can simply remove all such lines.