You are using type names as instance variables. For example:
return cash += Bet.payout(pool, sharkPool);
If Bet.payout() isn't a static method, then you need to create an instance of Bet first to call this method.
For example:
Bet b = new Bet();
return cash + b.payout(pool, sharkPool);
This appears to be the problem in a couple of different places.
EDIT: adding a few more suggestions.
Bet EmptyBet { get { return new Bet() { amount = 0, fish = 0, better = this }; }
The problem here is that you are using an instance reference (this
) inside of a static accessor. Think of a static member as the one and only copy of something. As such, it doesn't know about instances (i.e. specific, unique occurrences of a type).
I'm not sure what better
represents, but you can't assign it to this
, given the context.
EDIT #2: Here's a little class I mocked up to help you understand how to create a static member that will return a default bet.
public class Bet
{
#region instance members
public decimal Amount
{
get;
set;
}
public string Description
{
get;
set;
}
public void Payout()
{
// do something
}
#endregion
#region static members
public static Bet Empty
{
get
{
Bet b = new Bet();
b.Amount = 0M;
b.Description = "Default Empty Bet";
return b;
}
}
#endregion
}
EDIT #3: Declaring instance properties with accessors
//
// This will not compile because members have been defined more than once
public class Bet
{
// You can declare smart properties with default initializers
// by not declaring a body for the get/set accessors
public decimal Amount
{
get;
set;
}
public string Description
{
get;
set;
}
// OR, you can declare private variables and expose them
// publicly via get/set accessors. This gives flexibility
// in internal manipulation (sometimes) but creates more code
private decimal _amount = 0M;
public decimal Amount
{
get { return _amount; }
set { _amount = value; }
}
private string _description = string.Empty;
public string Description
{
get { return _description; }
set { _description = value; }
}
}
EDIT #4:
public void collect(int pool, int sharkPool)
{
return cash += betClass.payout(pool, sharkPool);
}
Error 4 Cannot implicitly convert type
'double' to 'int'. An explicit
conversion exists (are you missing a
cast?) Lab 3\Guy.cs 90 19 lab3
A double is a more precise type than an int (in a general manner of speaking). This means that it can't be implicitly "stuffed" into the memory space allocated for an int.
If you are using a double inside the Guy class, then you need to either change it to an int, or cast it where appropriate, or use doubles all the way through the process. A double allows for a decimal point, which would probably be needed in a real application that managed money (or better yet, the decimal type).
EDIT #5:
private int winningSharkTotal(int Winner)
{
int Result = 0;
for (int i = 0; i<3; i++)
{
Result += bets[i+(Winner*3)];
}
return Result;
}
Couple things wrong with this one...first, the casing of your variables is really confusing, because when most c# programmers see an uppercase variable name, it looks like a type, not a method parameter (notice how the SO editor formats it wrong).
Second thing, I don't know what logic you are trying to achieve with this:
bets[i+(Winner*3)]
Whatever i + (winner * 3)
equals will be the array index that is used. This is ambiguous at best. Perhaps you were trying to triple the winner's earnings?
Lastly, bet[index]
will return a Bet object, not an int. You need something more like bet[index].Amount
(or whatever the property you are using is).