tags:

views:

125

answers:

4

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!

+5  A: 

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).

Mark Byers
Thank you for your suggestions Mark. I do know how to understand compiler errors, it's just kind of hard to pick through them when you're presented with 60+ others. I will take your advice and look into what I have to accomplish.
classicrock985
@classicrock985: *it's just kind of hard to pick through them when you're presented with 60+ others* - That's why I suggest writing only a few new lines at a time. Then you will usually only get a handful of errors and as an added bonus you already know what line the problem is likely to be with (the line you just added). Also, fix (to the extent possible) the errors you have before adding more code.
Mark Byers
Another advantage of having correctly compiling code at all times is that intellisense will work correctly, allowing you to develop much faster. It really pays to fix the errors as soon as possible instead of writing 10s or 100s of lines of uncompiled / untested buggy code and then fixing all the errors afterwards.
Mark Byers
Thanks Mark, but I was building off of an already completed project, so it was generating other errors (if that makes sense). I do like to go error by error to see that my code is working correctly. Right now I'm struggling to do just that, and I feel like once I get those done my application still won't run. :(
classicrock985
Ok, my problem right now is that the raceBtn doesn't call to the Shark.Swim method like it should. That's the only error I have left! Any suggestions?It compiles without any errors, but the button doesn't do as it should anymore.
classicrock985
A: 

How about removing the ; in if (sharks[fish].Swim();)

Tseng
that's the function that actually runs my application.
classicrock985
but the semicolon is syntactically incorrect.
Pointy
Even with the semicolon gone it doesnt run that function (shark.Swim), which it's supposed to. Now it's at:if (sharks[i].Swim())
classicrock985
+1  A: 

Also

 if(sharkFinished = true) 

Should be:

 if(sharkFinished == true)

or just

 if(sharkFinished) 
mint
1+ Good one - I missed that one, and I think that won't even be a compile error.
Mark Byers
it was a compiler error. Thanks mint.I'm down to 5 errors, all because i and j aren't global variables, so I have to make it work somehow so that bets[i,j] is recognized in other functions/methods.
classicrock985
It would be EXTREMLY helpful if you post the compiler errors next time. They usually already tell you exactly what's wrong ^^
Tseng
A: 
        if(sharkFinished = true) 
        {
           place++;
        }

into

        if(sharkFinished == true) 
        {                 ^
           place++;
        }

that's comparison over assigning a value

Nico