2
u/1d3nt Oct 24 '19
The posts in this thread are shocking. People who question if a post is a homework are 99% of the time new programmers who hide behind th fact they cannot give an answer. ABitOffTheTop comment is one of the worst pointless replies I have seen in my 20+ years of programming. I have never seen such a stupid reply saying "left a bug". Ignoring the fact the code is terrible. What that translates to is "Iv posted you an example but it does not quite work, so I will pretend I am giving you a task" Urgh just urgh. If you can't help a user don't. "Still cheating though", what with that crap?
Ignoring this typical crap help from members who have likely been writing Visual Basic a couple weeks lets focus on a few issues.
Public Class Form1
Private Shared ReadOnly Rng As New Random
Private Sub Button1_Click() Handles Button1.Click
Dim isHeads = Rng.Next() Mod 2 = 0
PictureBox1.Visible = isHeads
PictureBox2.Visible = Not isHeads
' now what is the next steps?
End Sub
End Class0
u/ABitOffTheTop Oct 23 '19
I've left a fairly obvious bug in there, so best not submit it immediately if it is classwork. If you realise what the bug is, then you probably know enough to submit it. Still cheating though, but least you had to work for it..
Dim NumberOfFlips As Integer = 1000
Dim Heads As Integer
Dim rnd As New Random
Enum Coin
Heads
Tails
End Enum
Sub Main()
Dim CoinFlip = Function()
If (rnd.Next(2) = 1) Then
Return Coin.Heads
Else
Return Coin.Tails
End If
End Function
Dim CoinFlipRecorder = Function()
If (CoinFlip() = Coin.Heads) Then
Heads = Heads + 1
End If
Return CoinFlip()
End Function
For i = 1 To NumberOfFlips
Console.Write(CoinFlipRecorder() + " ")
Next
Console.WriteLine(Convert.ToString(NumberOfFlips) + " Coin Flips, " _
+ Convert.ToString(Heads) + " were heads and " _
+ Convert.ToString(NumberOfFlips - Heads) + " were tails")
End Sub
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.