Help with a program? - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Help with a program?

terrace89terrace89 Posts: 2Member
This is an untranslated version of what i need (Pseudo Code) I desperately need this

Bet=startbalance

Get users choice (Field, Craps, or Quit)

While they didn

Comments

  • Actor21Actor21 Posts: 35Member
    [code]
    program dice ;

    uses crt ;

    type
    choicetype = (FIELD, CRAPS, QUIT) ;

    function choice : choicetype ;
    {
    play or quit
    }
    var
    key : char ;

    begin
    write('F = FIELD. C = CRAPS. Q = QUIT') ;
    repeat
    key := upcase(readkey) ;
    until key in ['F', 'C', 'Q'] ;

    case key of
    'F' : choice := FIELD ;
    'C' : choice := CRAPS ;
    'Q' : choice := QUIT
    end ; { case }

    writeln
    end ;

    function getbet (balance : real) : real ;
    {
    get a valid bet
    }
    var
    bet : real ;

    begin
    while TRUE do begin { infinite loop }
    write('Enter bet amount ') ;
    readln(bet) ;
    if (bet <= 1000.0) and (bet <= balance) then begin
    getbet := bet ;
    exit
    end ;

    if bet > 1000.0 then
    writeln('Maximum bet is $1000.00')
    else if bet > balance then
    writeln('You do not have that much to bet.')
    end
    end ;

    function roll_dice : byte ;
    {
    simulate roll of two dice
    }
    begin
    roll_dice := random(6) + random(6) + 2
    end ;

    var
    start_balance,
    balance,
    bet,
    win_loss : real ;
    point,
    roll : byte ;

    begin
    randomize ;
    clrscr ;

    write('Enter starting balance ') ;
    readln(start_balance) ;
    balance := start_balance ;

    while TRUE do begin { infinite loop }
    case choice of
    FIELD : begin
    bet := getbet(balance) ;

    roll := roll_dice ;
    case roll of
    2,12 : begin
    win_loss := 2.0 * bet ;
    balance := balance + win_loss ;
    end ; { 2,12 }
    3,4,9,10,11 : begin
    win_loss := bet ;
    balance := balance + win_loss ;
    end ; { 3,4,9,10,11 }
    5,6,7,8 : begin
    win_loss := bet ;
    balance := balance - win_loss ;
    end ; { 5,6,7,8 }
    end ; { case }

    writeln('field', bet:10:2, roll:5, win_loss:10:2, balance:10:2)
    end ; { FIELD }

    CRAPS : begin
    bet := getbet(balance) ;

    roll := roll_dice ;
    case roll of
    2,3,12 : begin
    win_loss := bet ;
    balance := balance - win_loss ;
    writeln('field', bet:10:2, roll:5, win_loss:10:2, balance:10:2)
    end ; { 2,3,12 }
    7,11 : begin
    win_loss := bet ;
    balance := balance + win_loss ;
    writeln('craps ', bet:10:2, roll:5, win_loss:10:2, balance:10:2)
    end ; { 7,11 }
    4,5,6,8,9,10 : begin
    point := roll ;
    writeln('craps', bet:10:2, roll:5) ;
    textcolor(LIGHTRED) ;
    repeat
    roll := roll_dice ;
    writeln(roll:20)
    until (roll = point) or (roll = 7) ;
    textcolor(WHITE) ;

    if roll = point then begin
    win_loss := bet ;
    balance := balance+win_loss ;
    writeln(win_loss:25:2, balance:10:2)
    end
    else { roll is 7 } begin
    win_loss := bet ;
    balance := balance-win_loss ;
    writeln('craps', bet:10:2, roll:5, win_loss:10:2, balance:10:2)
    end
    end ; { 4,5,6,8,9,10 }
    end{ case }
    end ; { CRAPS }

    QUIT : begin
    writeln('Thank you for stopping by.') ;
    if start_balance > balance then begin
    writeln('You entered with ', start_balance:0:2, ' and you left with ', balance:0:2, '.') ;
    writeln('Thanks for the ', start_balance - balance:0:2, ' donation.')
    end
    else begin
    writeln('You entered with ', start_balance:0:2,' and you left with ', balance:0:2, '.') ;
    writeln('You gained ', balance - start_balance:0:2, ' dollars. Thanks for playing.')
    end ;
    break { exit infinite loop }
    end { QUIT }
    end { case }
    end
    end.
    [/code]
Sign In or Register to comment.