dont have time to test but i think its just storing the current scanf buffer char inside dummy then putting your n or y char inside answer.
when you scanf it stores the char you type as well as any other key (aka it also stores the enter key you pressed) but since you only accepted 1 char in the beginning ('y') the enter key is stored in the scanf buffer. what the second scanf statement simple clears the enter key in the scanf buffer and then puts the actual key you pressed inside answer.
ex:
scanf buffer: ""
does anyone have money
scanf buffer: "y{enter}"
put first char of buffer inside variable 'answer'
scanf buffer: "{enter}"
does anyone have money
scanf buffer: "{enter}y{enter}"
put first char of buffer inside dummer variable then second char of buffer inside answer
scanf buffer: "{enter}"
does anyone have money
scanf buffer: "{enter}y{enter}"
put first char of buffer inside dummer variable then second char of buffer inside answer
scanf buffer: "{enter}"
and it goes on.
hopefully you understand now.
a better way is to use the flushall(); function that flushes all the buffers. your new code would look like
Code
while (answer == 'y' || answer == 'Y') {
printf("Enter the amount of your donation.\n");
scanf("%lf",&value);
total += value;
flushall();
printf("Does anyone have any money?\n");
scanf("%c",&answer);
}
or something like that.
This post was edited by AbDuCt on Aug 31 2012 11:47am