tags:

views:

123

answers:

1

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

        }
    }
}

http://img251.imageshack.us/img251/3302/week1hw.jpg

[URL=http://img251.imageshack.us/i/week1hw.jpg/][IMG]http://img251.imageshack.us/img251/3302/week1hw.th.jpg[/IMG][/URL]

Uploaded with [URL=http://imageshack.us]ImageShack.us[/URL]

+1  A: 

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()
Kinderchocolate
Thanks for the help so far guys. I do see some stupid things I did as defining random twice. Boolean more should read true, with no quotes, instead of yes. I think I got caught up in the psuedocode and what my prof did himself and trying to combine them both. I'm going to try to write line for line and go from there. As far as my loop statements, are they ok?
Jay
Of course, it's ok. Please mark my solution as answer if you believe your problems have been solved.
Kinderchocolate