Reputation: 688
There's something wrong with my while loop (in my Form class), but basically, it tests to see who the winner of the "race" is in my application, and it also starts the application (Shark.Swim). Once it finds out who the winner is, it needs to get to the "payout" method in my Bet Class.
So here's what I have.
INSTANCE VARIABLES
private Shark[] sharks;
private Guy[] guys;
private Guy selectedGuy;
private Bet[,] bets;
private int[] winners = new int[4];
public Bet betClass;
public int selectedGuyIndex;
WHILE LOOP:
private void raceBtn_Click(object sender, EventArgs e)
{
public int[] finishingOrder = new int[4];
bool sharkFinished = false;
public int place = 1;
public int numSharksFinished;
while (numSharksFinished < 4)
{
sharkFinished = false;
for (int i = 0; i < 4; i++)
{
if (finishingOrder[i] == -1)
{
if (sharks[fish].Swim();)
{
finishedOrder[i] = place;
sharkFinished = true;
numSharksFinished++;
}
}
if(sharkFinished = true)
{
place++;
}
}
}
PAYOUT METHOD:
public double payout(int pool, int sharkPool)
{
for (int j = 0; j < 3; j++)
{
Guy[j].cash += Bets[i, j].Amount;
}
}
I think my best bet is moving the "payout" method to the main forms class, because there is no instance of the "Bets" Array in my Bet class. If you have any questions, ask away, and thanks in advance!
Upvotes: 0
Views: 327
Reputation: 838106
I can see quite a few errors. There should not be a semicolon here:
if (sharks[fish].Swim();)
^
You can't have public local variables. Either make them members, or remove the public keyword:
private void raceBtn_Click(object sender, EventArgs e)
{
public int[] finishingOrder = new int[4];
^^^^^^
This local (?) variable is not initialized before it is used:
public int numSharksFinished; // should't be public and is uninitialized
while (numSharksFinished < 4)
{
And I think that this should be changed to finishingOrder
:
finishedOrder[i] = place;
^^
It would be a good idea if you can read the compiler errors and learn how to understand them instead of posting all your errors to StackOverflow. It will allow you to develop programs much faster if you can understand what the compiler is trying to tell you.
I would also suggest writing programs in very small pieces, especially when you are just learning. Add only a few lines at a time and test those lines to make sure they work correctly (or at least make sure they compile) before adding more lines. This will help you to understand what code is causing the compile errors (usually it will be the code you just added / changed).
Upvotes: 5
Reputation: 48476
if(sharkFinished = true)
{
place++;
}
into
if(sharkFinished == true)
{ ^
place++;
}
that's comparison over assigning a value
Upvotes: 0
Reputation: 3433
Also
if(sharkFinished = true)
Should be:
if(sharkFinished == true)
or just
if(sharkFinished)
Upvotes: 2