See here:
puts("Do u want to play the dice rolling game again (Y/N)?");
scanf(" %c", &answer);
answer = toupper(answer);
if(answer =='y')
{
continue;
}
else
{
break;
}
} while(answer =='Y');
There are 3 mistakes here:
1) the
if
block tests against a lower case 'y', but you've previously set
answer
tu uppercase
2) th
if
block is unneeded, as it duplicates the test of the
do...while
loop, error 1 notwithstanding
3)
scanf("%c", &answer)
is not going to do what you expect. The first time through the loop, it will read the first character from the input buffer. Lets assume that its a y and so the loop continues on. The next time through the loop the
scanf()
call will read the next char in the input buffer. In this case it will be the newline ('\n') from the previous input, or if the user entered 'yes', then the
scanf()
call will return 'e' from the input buffer. Better to read the entire input buffer (e.g. scanf("%s", buffer)), and then test the first char.