consecutive coin flip ISSUE - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

consecutive coin flip ISSUE

spencerwazspencerwaz Posts: 2Member
HERE IS A COPY OF THE PROGRAM







#include
//coin toss average
//spnecer wazlavek

main()

{



int iTemp = ''; //temporary flip value
int iGoal = ''; //consecutive goal
int iCnt = 0; //flip counter
int iFlp = 0; //current consecutive flips


printf("

Please input the consecutive count you would like to acheive:");


scanf("%d", &iGoal); // how many coin flips


do
{

iTemp = (rand() % 2); //heads or tails rep by 0,1

printf("%d
", iTemp); //debug purposes

if (iTemp = 1) //beginning of if
{

iFlp++; //current consecutive flips

}

else

{

iFlp = 0; // reset flip if un-consecutive

}// end of if



iCnt++; //count up 1
iTemp = ''; //reset the coin


printf("consecutive flip atm is %d and count is %d", iFlp, iCnt); //added to print the consecutive flips

}
while (iGoal != iFlp); //end of do-while

printf("

It took %d flips to obtain %d wins in a row", iCnt, iGoal); //reasult
}// end of prog







added plenty of comments to give you a step by step..

The issue that i am having is that the flip counter counts correctly up until the last printf and then it just displays the goal rather than the iCnt integer.


please please help :) much appreciated

Comments

Sign In or Register to comment.