r/visualbasic • • Oct 23 '19

VB.NET Help Coin flipping program

Post image
5 Upvotes

8 comments sorted by

View all comments

1

u/C4_Ghost Oct 23 '19

So Ive been trying to add a count of how many times heads and tales have been flipped. I'm sure its probably simple but Ive been at this for about 10 hours. Any help would really be appreciated.

4

u/sa_sagan VB.Net Master Oct 23 '19

You need to add two new integer variables outside of Button1_Click.

Then when tails, add 1 to the tails integer, and when heads, add 1 to the heads integer.

I have assumed this is homework so I won't write the code for you, but that should give you an idea of what to do.

1

u/C4_Ghost Oct 23 '19

Wow..... How come they have to be global variables in order to count?

3

u/sa_sagan VB.Net Master Oct 23 '19

Because once the Button1_Click event has finished, every value inside of there will cease to exist.

Therefore you store your counting variables elsewhere, so you can reference them inside of Button1_Click and increase their values without losing them when it's finished.