Hello all, I'm having some trouble with a project I am doing and I was wandering if anybody could help me/point me in the right direction.
So the gist of what is happening is I have a program that is supposed to be flipping 2 coins independently of each other but each coin always mirrors the others result.
Hear is the 2 pieces of code.
first of all the code to flip the coin.
class Coin {
private const int HEADS = 0;
private const int TAILS = 1;
private int face;
/// <summary>
/// Random class object used to generate random numbers
/// Look at Random class for description of methods available
/// </summary>
private Random random = new Random();
//-----------------------------------------------------------------
// Sets up the coin by flipping it initially.
//-----------------------------------------------------------------
public Coin() {
Flip();
}
//-----------------------------------------------------------------
// Flips the coin by randomly choosing a face value.
//-----------------------------------------------------------------
public void Flip() {
face = random.Next(2);
}
//-----------------------------------------------------------------
// Returns true if the current face of the coin is heads.
//-----------------------------------------------------------------
public bool IsHeads() {
return (face == HEADS);
}
//-----------------------------------------------------------------
// Returns the current face of the coin as a string.
//-----------------------------------------------------------------
public override string ToString() {
string faceName;
if (IsHeads()) {
faceName = "Heads";
} else {
faceName = "Tails";
}
return faceName;
}
}
}
and here is the code to flip two coins
class TwoUp : Coin {
private Coin coin1 = new Coin();
private Coin coin2 = new Coin();
Anybody now why the mirror the same results 100% of the time, i.e.
tails tails / heads heads and never a combination of the two.