Hack Forums
[C#] C# calculate drop rate of sandwhiches - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [C#] C# calculate drop rate of sandwhiches (/showthread.php?tid=5922223)



C# calculate drop rate of sandwhiches - Carlsson94 - Dec 24, 2018

I have a school assignment that I would like to get done, however, I have issues trying to reach my teacher during the holidays.

I'm supposed to check if I drop 100 sandwiches how many of them will fall the right way up?

I have a slider where I can change my % value, but I'm not sure how I would do the calculation. Id assume I would do this in a for loop I have a slider where I get the Fortune value called: FortuneValue

[Image: Yjh0k.png]


PHP Code

<?php 
int rightWay 
= 0;
int wrongWay = 0;
int tries = Convert.ToInt32(Tries.Text);


for (
int i = 0; i < tries; i++)
{
} 



RE: C# calculate drop rate of sandwhiches - BahNahNah - Dec 24, 2018

Is the slider how much chance it will be the right way up?
Code
rightWay = ammountdropped * (percentChanceOfBeingRightWayUp / 100)

and the wrong way is the rest. Basic math yo.


RE: C# calculate drop rate of sandwhiches - Carlsson94 - Dec 24, 2018

(Dec 24, 2018 04:34 AM)BahNahNah Wrote:  Is the slider how much chance it will be the right way up?
Code
rightWay = ammountdropped * (percentChanceOfBeingRightWayUp / 100)

and the wrong way is the rest. Basic math yo.

Thats what I did before the holidays, how ever I failed. I was told "Note that probability is not the same as actual outcome".
Meaning if I drop 100 sandwhiches and I have only have a 50% chance not everyone will land the right way up

Because I did this
Code
int tries = Convert.ToInt32(Tries.Text);

            //Mackor åt rätt håll
            int rightWay = (int) (tries * (FortuneValue.Value / 100));
            //Mackor åt fel håll
            int wrongWay = FindDifference(rightWay, tries);



RE: C# calculate drop rate of sandwhiches - BahNahNah - Dec 24, 2018

(Dec 24, 2018 04:41 AM)Carlsson94 Wrote:  Thats what I did before the holidays, how ever I failed. I was told "Note that probability is not the same as actual outcome".
Meaning if I drop 100 sandwhiches and I have only have a 50% chance not everyone will land the right way up

Because I did this
Code
           int tries = Convert.ToInt32(Tries.Text);

           //Mackor åt rätt håll
           int rightWay = (int) (tries * (FortuneValue.Value / 100));
           //Mackor åt fel håll
           int wrongWay = FindDifference(rightWay, tries);

For each attempt, check the probability that it is the right way up. For example, 50/50
Code
for(i = 0; i < numberofflips; i++){
    if(rnd.Next(0, 2) == 0){
        rightway++;
    }else{
        wrongway++;
    }
}



RE: C# calculate drop rate of sandwhiches - Carlsson94 - Dec 24, 2018

(Dec 24, 2018 05:41 AM)BahNahNah Wrote:  For each attempt, check the probability that it is the right way up. For example, 50/50
Code
for(i = 0; i < numberofflips; i++){
   if(rnd.Next(0, 2) == 0){
       rightway++;
   }else{
       wrongway++;
   }
}

Now I just have too implement my Fortune slider, but I think I'm on the right path, cheers!