Pascal

Moderators: None (Apply to moderate this forum)
Number of threads: 4106
Number of posts: 14016

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Help with a program? Posted by terrace89 on 7 Nov 2012 at 6:54 PM
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’t choose quit

If they chose field

Get the persons bet

Until it is valid (not greater than 1000, not negative, not more money than they have)

Roll dice

If roll is 2 or 12

Winloss= twice the bet

Newbalance=balance+winloss

Show balance,’ field’, bet, roll, winloss, newbalance

Balance=newbalance

If roll is 3, 4,9,10, or 11

Winloss=bet

Newbalance=balance+winloss

Show balance,’ field’, bet, roll, winloss, newbalance

Balance=newbalance

If roll is 5, 6, 7, or 8

Winloss=bet

Newbalance=balance-winloss

Show balance,’ field’, bet, roll, winloss, newbalance

Balance=newbalance

If they chose craps

Get the persons bet

Until it is valid (not greater than 1000, not negative, not more money than they have)

Roll dice

If roll is 2, 3, or 12

Winloss=bet

Newbalance=balance-winloss

Show balance,’craps’, bet, roll, winloss, newbalance

Balance=newbalance

If roll is 7 or 11

Winloss=bet

Newbalance=balance+winloss

Show balance,’craps’, bet, roll, winloss, newbalance

Balance=newbalance

If roll is 4, 5, 6, 8, 9, or 10

Roll=point

Show balance, ’craps’, bet, roll

Repeat

Roll dice

Show roll

Until

Roll is point

Winloss=bet

Newbalance=balance+winloss

Show winloss, newbalance

Balance=newbalance

Else

Roll is 7

Winloss=bet

Newbalance=balance-winloss

Show balance,’craps’, bet, roll, winloss, newbalance

Balance=newbalance

If they chose quit

Write ‘thank you for stopping by.

If (startbalance>balance)

Write ‘you entered with’, startbalance, ’and you left with’, balance.

Write ‘thanks for the’, startbalance-balance, ‘donation.’

If (startbalance<balance)

Write ‘you entered with’, startbalance,’and you left with’, balance.

Write ‘You gained’, balance-startbalance,’dollars. Thanks for playing.’





Report
Re: Help with a program? Posted by Actor21 on 16 Nov 2012 at 2:10 PM
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.




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.