That is what it started out as.

Start Main( )
Get name of player
Get cash (starting cash amout)
Set more = “yes”
Start Loop
Set betAmount = 0;
Start Loop
Get betAmount
If( betAmount > cash )
Display “You do not have enough cash for that bet amount.”
Display “Cash: ” & cash
End If
While( betAmount > cash ), continue looping
Display “Press Enter to draw a card.”
Generate a random number from 2 to 14 and place in player variable
Call DisplayCard( player )
Display “Press Enter to see the dealer’s card.”
Create a random number between 2 and 14 and place in dealer variable
Call DisplayCard( dealer )
Call Evaluate( player, dealer ) that returns a boolean (true if player wins)
If player wins then
Display name & “, you win!”
Increase cash by the betAmount
Otherwise
Display name & “, you lose”
Decrease cash by the betAmount
End If
If cash > 0 then
Display “You have ” & cash & “ cash in hand.”
Get more with prompt “Play again? (yes/no): ”
Otherwise
Display “You are out of cash.”
Set more = “no”
End If
While more = “yes”, continue looping
Display “Thanks for playing.”
Stop



Start DisplayCard( card as integer )
If card = 14 then
Display “Ace”
Otherwise if card = 13 then
Display “King”
Otherwise if card = 12 then
Display “Queen”
Otherwise if card = 11 then
Display “Jack”
Otherwise if card >= 2 AND card <= 10 then
Display card
Otherwise
Display “Error: ” & card & “is not valid.”
End If
Stop



Start Evaluate( player, dealer )
If player > dealer then
Return true
Otherwise if dealer > player then
Return false
Otherwise
Display “Tie.  We go to WAR!”
Display “Press Enter to draw a card.”
Generate a random number between 2 and 14 and place in player variable
Call DisplayCard( player )
Display “Press Enter to see the dealer’s card.”
Create a random number between 2 and 14 and place in dealer variable
Call DisplayCard( dealer )
Return result of Evaluate( player, dealer ) –recursion will continue until someone wins
End If
Stop


This is what I have came up with so far.


using System;
using System.Collections.Generic;
using System.Text;


namespace Lab1
{
public class Program
{
static Random rgen = newRandom();
public static void Main(string[] args)
{
string name = "";
double cash = 0.0;
int more = "yes";
{
string betAmount = 0;
do
{
if (betAmount > cash)
{
Console.WriteLine("You do not have enough cash for that bet.");
Console.WriteLine("Cash:" & cash);
}
}
while (betAmount > cash);
Console.WriteLine("Press Enter to draw a card.");
player = rgen.Next(2, 15);
DisplayCard(player);
Console.WriteLine("Press Enter to see dealer's card");
player = rgen.Next(2, 15);
DisplayCard(dealer);
bool playerwon = Evaluate(player, dealer);
if (playerWon)
{
Console.WriteLine("name(), you win!");
cash = cash + betAmount;
}
{
if (playerLost)
Console.WriteLine("name(), you loose");
cash = cash - betAmount;
}
if (cash > 0)
{
Console.WriteLine("You have", cash, "cash in hand");
int more = ("play again? (yes/no");
}
if (cash < 0)
{
Console.WriteLine("You are out of cash");
more = "no";
}
while (more = "yes") ;
Console.WriteLine("Thanks for playing");
}
}
}
public static void displayCard(int card)
{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 AND card <= 10)
Console.WriteLine("card");
else
console.WriteLine("error: card is not valid");
}


public static bool Evaluate(int player, int dealer);
if (player > dealer)
Console.ReadLine("true");
else if (dealer > player)
Console.ReadLine("false");
else if
Console.WriteLine("Tie. We go to WAR!");
Console.WriteLine("Press Enter to draw a card");
player = rgen.Next(2,15);
displayCard(player)
Console.WriteLine("Press enter to see the dealer's card."),
player = rgen.Next(2,15);
displayCard(dealer)
Evaluate(player, dealer);
}
}

The second method it says the void shouldn't be there and the third method it says the bool shouldn't be the and at the end it says end of file expected. Not sure how to fix this.

Edited 3 Years Ago by happygeek: fixed formatting

Charlie,

That is some messed up code you have there.
Looks like maybe you were trying to convert a VB app to C#.

I rarely write console apps, so there maybe some shortcuts, but the version below works.
I took the liberty of loading the players account with 10 bucks, and charging a buck to play a round.

Hope this helps:

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static Random rgen = new Random();

        static void Main(string[] args)
        {
            double cash = 10.0;
            int player;
            int dealer;
            double betAmount = 1.0;

            while( betAmount <= cash )
            {
                Console.WriteLine("Press Enter to draw a card.");
                Console.ReadLine();
                player = rgen.Next(2, 15);
                displayCard(player);
                Console.WriteLine("Press Enter to see dealer's card");
                Console.ReadLine();
                dealer = rgen.Next(2, 15);
                displayCard(dealer);

                if (Evaluate(player, dealer))
                {
                    Console.WriteLine("name(), you win!");
                    cash += (betAmount * 2);
                }
                else
                {
                    Console.WriteLine("you loose");
                    cash -= betAmount;
                }

                if (cash > 0)
                {
                    Console.WriteLine( string.Format("You have ${0} cash in hand",cash));
                    Console.WriteLine("play again? (yes/no) ");
                    string more = Console.ReadLine();
                    if (more == null || more.Length == 0 || more.Substring(0,1).ToLower() != "y" )
                        break;
                }
                else
                    break;
                
            }

            if (betAmount > cash)
            {
                Console.WriteLine("You do not have enough cash for that bet.");
                Console.WriteLine(string.Format("Cash: {0}", cash));
            }
            Console.WriteLine("Thanks for playing");

        }

        public static void displayCard(int card)
        {
            switch (card)
            {
                case 14: Console.WriteLine("Ace"); break;
                case 13: Console.WriteLine("King"); break;
                case 12: Console.WriteLine("Queen"); break;
                case 11: Console.WriteLine("Jack"); break;
                default:
                    if (card >= 2 && card <= 10)
                        Console.WriteLine(card);
                    else
                        Console.WriteLine("error: card is not valid");
                    break;
            }
        }

        public static bool Evaluate(int player, int dealer)
        {
            if (player > dealer)
            {
                Console.WriteLine("Win");
                return true;
            }
            else if (dealer > player)
            {
                Console.WriteLine("Lose");
                return false;
            }
            else
            {
                Console.WriteLine("Tie. We go to WAR!");
                Console.WriteLine("Press Enter to draw a card");
                Console.ReadLine();
                player = rgen.Next(2, 15);
                displayCard(player);
                Console.WriteLine("Press enter to see the dealer's card.");
                Console.ReadLine();
                player = rgen.Next(2, 15);
                displayCard(dealer);
                return Evaluate(player, dealer);
            }
        }

    }

}

// Jerry

This article has been dead for over six months. Start a new discussion instead.