开发者

C# Casino Program Homework [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not ge开发者_如何学JAVAnerally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 9 years ago.

Listed below is my program. I'm supposed to take two cards of both the dealer and player and evaluate who has the higher card. The player bets a certain amount of cash against that bet, and of course, if he wins he wins what was bet, if he loses, he loses the cash. I seemed to have followed the psuedocode correctly, but I keep receiving errors. Anyone want to guide me in what I'm doing wrong? Please and thank you for responses. The errors are followed by the 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's Name: ");
            playerName = Console.ReadLine();


            Console.WriteLine("Please Enter {0}'s 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);

        }
    }
}

C# Casino Program Homework [closed]


I copied and pasted your code into Visual Studio.

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

  • Boolean more = "yes"; (not making sense)
  • Random r = new Random(); (it has already been defined)
  • return card in DisplayCard() because it is a void function
  • Define winner in Evaluate()
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜