Extrn GetDec:Far, PutDec:Far, PutDec:Far, Putstrng:Far, NewLine:Far ; #include "iostream.h" Data Segment ;######Game variables########### CASH dw -5551 ;cash in cents DAY dw 1 GlassesSold dw ? PriceperGlass dw -56 Income dw ? Expenses dw ? GlassesMade dw ? AdvertisingMade dw ? AdvertisingCost dw 15 Profit dw ? Assets dw ? CurrentAssets dw ? DaystoPlay dw ? weathercond dw ? ;######inputforday function prompts###### OnDay db "On day " ; length 7 LemonadeCost db ", The Cost of Lemonade is " ; length 26 ;######Random number function vars###### RAND_k dw 369 RAND_seed dw ? ;######prompts######### intro db "Welcome to lemonade stand" ;basic intro prompt 25 weather db 'Todays weather is' ;weather report 17 dailystatement db 'Lemonade stand Daily Statement:' ;daily statement 31 date db 'On day: ' ;day output sales db 'Glasses sold: ' ; glasses sold 14 priceprompt db 'Price per glass: ' ; price per glass 17 production db 'Glasses made: ' ; glasses made 14 advertsprompt db 'Signs made: ' ; signs made 12 profitprompt db 'Profit: ' ;profit prompt 8 AssetsPrompt db 'Assets: ' ;asset prompt 8 glassesprompt db 'How many glasses of lemonade to you wish to make? ';length 50 advertisingprompt db 'How many advertising signs do you wish to make (15 cents each)? ' ;64 lemonadepriceprompt db 'What price (in cents) do you wish to charge for lemonade? '; 56 daysprompt db 'Please enter the number of days to run the stand (1-30): ' ; 57 numberoutofrange db "Number out of range, try again" ; 30 ;########Weather report######## weather0 db 'Todays weather is hot and humid' ;32 weather1 db 'Todays weather is sunny' ;24 weather2 db 'Todays weather is fair' ;23 weather3 db 'Todays weather is cloudy and cool' ;34 weather4 db 'Todays weather is raining' ;26 Data Ends Code Segment Assume Cs:Code, Ds:Data, Ss:Sseg ;#####Convert to Dollar####### ;takes 1 value converts it front cents ;to dollars ;Returns Whole # in Ax ;Cents # in DX @CentstoDollars Proc Near C, @CASH:WORD push Bx xor dx,dx mov Ax, @Cash cwd mov Bx, 100 iDiv Bx pop Bx @ctdif: cmp Dx, 0 jl @ctdthen jmp @ctdendif @ctdthen: neg Dx jmp @ctdendif @ctdendif: ret @CentstoDollars Endp ;#####random number generator####### ;gets a large number, a seed, and an upper limit ;seed is wiped out initially ;system time is used for seed ;answer is returned in Ax @RANDOMNUMBER Proc Near C, @high:word push Bx push Cx push Dx xor Ax, Ax ;clear AX mov ah, 2Ch ;load 2Ch into ah int 21h ;load system time into registers mov RAND_seed, Dx ;dh holds seconds, dl holds ms, move to seed mov bx, @high add bx, 1 mov ax, RAND_seed xor dx,dx cwd div bx mov ax, dx pop Dx pop cx pop Bx ret @RANDOMNUMBER ENDp ;####ClearScreen###### ;clears the screen with a loop ;puts @line # of new lines on the screen @cLEARSCREEN Proc Near C, @lines:word push Ax push Bx push Cx push Dx mov Bx, @lines @CSfor: cmp bx, 0 ja @CSdo jmp @CSendfor @CSdo: call newline dec Bx jmp @CSfor @CSendfor: pop Dx pop Cx pop Bx pop Ax ret @CLEARSCREEN ENDp ;######outputs cents formated nicely##### ;outputs -3453 or 300 as $34.53 or $3.00 ;input is money in cents @outputdollars Proc Near C, @money:word push ax push bx push cx push dx invoke @CentstoDollars, @money ;break money apart into ;dollars and cents push Ax push dx xor ax, ax xor dx, dx mov ah, 02h mov Dl, 36 int 21h pop Dx pop Ax @optif2: cmp @money, 0 jl @optand2 jmp @optendif2 @optand2: cmp @money, -100 jg @optthen2 jmp @optendif2 @optthen2: push Ax push dx xor ax, ax xor dx, dx mov ah, 02h mov Dl, 45 int 21h pop Dx pop Ax jmp @optendif2 @optendif2: call putdec push Ax push dx xor ax, ax xor dx, dx mov ah, 02h mov Dl, 46 int 21h pop Dx pop Ax mov Ax, Dx @optif: cmp Ax, 10 Jb @optthen jmp @optendif @optthen: push Ax mov Ax, 0 call putdec pop Ax jmp @optendif @optendif: call putdec pop dx pop cx pop bx pop ax ret @outputdollars ENDp @InputForDay Proc Near C push ax push bx push cx push dx Mov Cx, 7 Lea Di, onday Call Putstrng mov Ax, DAY call putdec Mov Cx, 26 Lea Di, lemonadecost Call Putstrng invoke @outputdollars, PricePerglass call newline Mov Cx, 7 Lea Di, assetsprompt Call Putstrng invoke @outputdollars, CASH call newline Mov Cx, 50 Lea Di, glassesprompt Call Putstrng call getdec mov GlassesMade, Ax call newline Mov Cx, 64 Lea Di, advertisingprompt Call Putstrng call getdec mov advertisingmade, Ax call newline Mov Cx, 58 Lea Di, lemonadepriceprompt Call Putstrng call getdec mov priceperglass, Ax pop dx pop cx pop bx pop ax ret @InputForDay endp ;#######Asset Statement############ @AssetStatement Proc Near C push cx push ax invoke @clearscreen, 25 mov cx,31 lea di,dailystatement call putstrng call newline mov cx,8 lea di,date call putstrng mov ax,day call putdec call newline mov cx,14 lea di,sales call putstrng mov ax,GlassesSold call putdec call newline mov cx,17 lea di,priceprompt call putstrng invoke @outputdollars,PriceperGlass call newline mov cx,14 lea di,production call putstrng mov ax,GlassesMade call putdec call newline mov cx,12 lea di,advertsprompt call putstrng mov ax,AdvertisingMade call putdec call newline mov cx,8 lea di,profitprompt call putstrng invoke @outputdollars,Profit call newline lea di,assetsprompt call putstrng invoke @outputdollars,assets call newline pop cx pop ax ret @AssetStatement ENDp @PromptforDays proc near C push cx push ax @pfdfor: mov cx,57 lea di,daysprompt call putstrng call getdec cmp ax,30 jg @pfdtryagain cmp ax,0 jle @pfdtryagain jmp @endfor @pfdtryagain: mov cx,30 lea di,numberoutofrange call putstrng call newline jmp @pfdfor @pfdendfor: mov DaystoPlay,ax pop cx pop ax ret @promptforDays endp ;########Generate weather report######## ;Generates the weather report for the day @GenerateWeather Proc near C push ax push bx push cx push dx invoke @randomnumber, 4 @gswitch: cmp ax, 0 je @gcase0 cmp ax, 1 je @gcase1 cmp ax, 2 je @gcase2 cmp ax, 3 je @gcase3 cmp ax, 4 je @gcase4 jmp @gdefault @gcase0: Mov Cx, 31 Lea Di, weather0 Call Putstrng Call Newline mov weathercond, 0 jmp @gendswitch @gcase1: Mov Cx, 23 Lea Di, weather1 Call Putstrng Call Newline mov weathercond, 1 jmp @gendswitch @gcase2: Mov Cx, 22 Lea Di, weather2 Call Putstrng Call Newline mov weathercond, 2 jmp @gendswitch @gcase3: Mov Cx, 33 Lea Di, weather3 Call Putstrng Call Newline mov weathercond, 3 jmp @gendswitch @gcase4: Mov Cx, 26 Lea Di, weather4 Call Putstrng Call Newline mov weathercond, 4 jmp @gendswitch @gdefault: @gendswitch: pop dx pop cx pop bx pop ax ret @generateweather endp main Proc Far MOV AX,SEG DATA MOV DS,AX MOV ES,AX invoke @clearscreen, 20 Mov Cx, 25 Lea Di, intro Call Putstrng Call Newline invoke @promptfordays @for: cmp DaystoPlay,0 jg @do jmp @endfor @do: invoke @generateweather endfor: Mov Ah, 4Ch Int 21h main Endp Mov Ah, 4Ch Int 21h main Endp Code Ends SSeg Segment STACK DB 254 dup(?) SSeg Ends End main