C Programming. Coin Flip Program Loop Not Working Like I Want It To
<p>So im supposed to make a coin flipping program and I did everything properly but im supposed to make it so that it keeps looping until the user enters 0. I have done this but everytime the program loops, the outputs of heads and tails don't reset. I run the program, it asks how many times I want the coin to be flipped, and I enter 5. Then it gives me say 3 heads and 2 tails, and then loops again asking me the same question. I enter 5 again, but now the results are 7 Heads and 3 Tails. But I only asked for it to be flipped 5 times, so its adding the old head/tail count to the new one, when i just want a fresh count. Im pretty sure its a simple fix but please help. Heres the code:</p>

<pre><code>for (;;) {

printf("How many times do you want to flip the coin? (Press 0 to exit));
scanf("%d", &amp;toss);                 

if (toss == 0) {
printf("Thank you for using the program!\n");
break;                  //terminates program if toss = 0
}

puts (" ");

for ( counter = 0; counter &lt; toss; counter++ ) 
{
        if (flip( ) == 0)       //call the function flip
        heads++;

        else
        tails++;
}                   //end of for loop

printf( "Heads Was Flipped %d Times\n", heads );
printf( "Tails Was Flipped %d Times\n", tails );

continue;
return 0;
</code></pre>