C # Casino Homework Program

Below is my program. I have to take two cards from both the dealer and the player and evaluate who has the highest card. The player bets on a certain amount of money against this bet, and, of course, if he wins, he wins what was bet, if he loses, he loses money. I seem to be following psuedocode correctly, but I get errors all the time. Does anyone want to guide me in what I am doing wrong? Please thank you for the answers. Errors are followed by a code.

using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Casino_War { class Program { static void Main(string[] args) { string playerName; double cash, betAmount; int player, dealer; Console.Write("Please Enter Player Name: "); playerName = Console.ReadLine(); Console.WriteLine("Please Enter {0} Cash Amount", playerName); cash = double.Parse(Console.ReadLine()); Boolean more = "yes"; do { betAmount = 0; Console.WriteLine("Please Enter The Bet Amount: "); betAmount = double.Parse(Console.ReadLine()); if (betAmount > cash) { Console.WriteLine("You Do Not Have Enough Cash For That Bet Amount."); Console.WriteLine("Cash: {0:C}", cash); } while (betAmount > cash) { Console.WriteLine("Press Enter To Draw A Card."); Console.ReadKey(); Random r = new Random(); player = r.Next(1, 15); DisplayCard(player, "Player"); Console.WriteLine("Press Enter To Draw A Dealer Card."); Console.ReadKey(); Random r = new Random(); dealer = r.Next(1, 15); DisplayCard(dealer, "Dealer"); } private static void EvaluateCash(ref double betAmount, double cash, Boolean winner, string playerName) { if (winner) { Console.WriteLine("{0} You Won {1:C}!", playerName, betAmount); cash = betAmount + cash; } else { Console.WriteLine("{0} You Lose {1:C}!", playerName, betAmount); cash = cash - betAmount; } Console.WriteLine("You Now Have {0:C}", cash); } private static Boolean PlayAgain(double cash, double betAmount, string playerName, Boolean more) { if (cash > 0) { Console.WriteLine("You Have {0} Cash In Hand.", cash); Console.WriteLine("\nPlay Again (Y/N)? "); more = Console.ReadLine().ToUpper(); Console.WriteLine("\n\n"); } while (more == "Y"); Console.WriteLine("Thanks For Playing!"); } public static void DisplayCard(int card) { int card = r.Next(2, 14); if (card == 14) Console.WriteLine("Ace"); else if (card == 13) Console.WriteLine("King"); else if (card == 12) Console.WriteLine("Queen"); else if (card == 11) Console.WriteLine("Jack"); else if (card >= 2 && card <= 10) return card; else Console.WriteLine("Error: {0} Is Not Valid.", card); return card; } static void Evaluate(int player, int dealer) { if (player > dealer) winner = true; else if (dealer > player) winner = false; else Console.WriteLine("Tie. We Go To WAR!"); Console.WriteLine("Press Enter To Draw A Card."); Console.ReadKey(); Random r = new Random(); player = r.Next(1, 15); DisplayCard(player, "Player"); Console.WriteLine("Press Enter To Draw A Dealer Card."); Console.ReadKey(); Random r = new Random(); dealer = r.Next(1, 15); DisplayCard(dealer, "Dealer"); return Evaluate(player, dealer); } } } 

enter image description here

+4
source share
1 answer

I copied and pasted your code in Visual Studio.

Before worrying about the {bracket syntax error, you need to think and fix:

  • Boolean more = "yes"; (doesn't make sense)
  • Random r = new Random (); (it is already defined)
  • in DisplayCard () because it is a void function
  • Determine the winner in Evaluate ()
+4
source

All Articles