winforms - Why am I getting these errors in C#? -
edit:
i got rid of of errors. help.
there's wrong while loop (in form class), basically, tests see winner of "race" in application, , starts application (shark.swim). once finds out winner is, needs "payout" method in bet class.
so here's have.
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; (int = 0; < 4; i++) { if (finishingorder[i] == -1) { if (sharks[fish].swim();) { finishedorder[i] = place; sharkfinished = true; numsharksfinished++; } } if(sharkfinished = true) { place++; } } }
payout:
public double payout(int pool, int sharkpool) { (int j = 0; j < 3; j++) { guy[j].cash += bets[i, j].amount; } }
i think best bet moving "payout" method main forms class, because there no instance of "bets" array in bet class.
you using type names instance variables. example:
return cash += bet.payout(pool, sharkpool);
if bet.payout() isn't static method, need create instance of bet first call method.
for example:
bet b = new bet(); return cash + b.payout(pool, sharkpool);
this appears problem in couple of different places.
edit: adding few more suggestions.
bet emptybet { { return new bet() { amount = 0, fish = 0, better = }; }
the problem here using instance reference (this
) inside of static accessor. think of static member 1 , copy of something. such, doesn't know instances (i.e. specific, unique occurrences of type).
i'm not sure better
represents, can't assign this
, given context.
edit #2: here's little class mocked understand how create static member return default bet.
public class bet { #region instance members public decimal amount { get; set; } public string description { get; set; } public void payout() { // } #endregion #region static members public static bet empty { { bet b = new bet(); b.amount = 0m; b.description = "default empty bet"; return b; } } #endregion }
edit #3: declaring instance properties accessors
// // not compile because members have been defined more once public class bet { // can declare smart properties default initializers // not declaring body get/set accessors public decimal amount { get; set; } public string description { get; set; } // or, can declare private variables , expose them // publicly via get/set accessors. gives flexibility // in internal manipulation (sometimes) creates more code private decimal _amount = 0m; public decimal amount { { return _amount; } set { _amount = value; } } private string _description = string.empty; public string description { { 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' 'int'. explicit conversion exists (are missing cast?) lab 3\guy.cs 90 19 lab3
a double more precise type int (in general manner of speaking). means can't implicitly "stuffed" memory space allocated int.
if using double inside guy class, need either change int, or cast appropriate, or use doubles way through process. double allows decimal point, needed in real application managed money (or better yet, decimal type).
edit #5:
private int winningsharktotal(int winner) { int result = 0; (int = 0; i<3; i++) { result += bets[i+(winner*3)]; } return result; }
couple things wrong one...first, casing of variables confusing, because when c# programmers see uppercase variable name, looks type, not method parameter (notice how editor formats wrong).
second thing, don't know logic trying achieve this:
bets[i+(winner*3)]
whatever i + (winner * 3)
equals array index used. ambiguous @ best. perhaps trying triple winner's earnings?
lastly, bet[index]
return bet object, not int. need more bet[index].amount
(or whatever property using is).
Comments
Post a Comment