I've always enjoyed the old random stock market type games, so I decided one day that to help waste my time to make a small stock market game in Perl. I was hoping that you could help point out errors or things that could have been done much easier ect.

Well here it is...

#!/usr/bin/perl -w use strict; my($dif,$randNumber,$manip,$whichstock,$howmany,$goal,$date,$derpco,$t +etrabytz,$mojoinc,$freke,$mega,$cash,@stocks,$buy,$sell,$buynum,$sell +num,$trans); @stocks = (0,0,0,0,0); sub genRand { my $startNumber = shift(); my $endNumber = shift(); my $randNumber = int($startNumber + rand() * ($endNumber - $startNumbe +r)); return $randNumber; }; print "What Goal In Cash Do You Want To Set? :"; chomp ($goal=<STDIN>); print "Thanks\n\n"; $date=1; $derpco=genRand(10,100); $tetrabytz=genRand(10,100); $mojoinc=genRand(10,100); $freke=genRand(10,100); $mega=genRand(10,100); $cash=genRand(500,1000); until ($cash > $goal or $date == 31) { $date=$date+1; $manip=genRand(0,50); $derpco=$derpco+genRand(-10,10); $tetrabytz=$tetrabytz+genRand(-40,40); $mojoinc=$mojoinc+genRand(-20,20); $freke=$freke+genRand(-25,25); $mega=$mega+genRand(-35,35); if ($derpco < 1){$derpco = 0; $stocks[0]=0; }; if ($tetrabytz < 1){$tetrabytz = 0; $stocks[1]=0;}; if ($mojoinc < 1){$mojoinc = 0; $stocks[2]=0;}; if ($freke < 1){$freke = 0; $stocks[3]=0;}; if ($mega < 1){$mega = 0; $stocks[4]=0;}; if ($date == 30) {print "Last Day!! better sell your stock"}; if ($manip == 5) {print "there is a small market error in your favor!\ +n\n"; $whichstock=genRand(0,4); $howmany=genRand(1,10); $stocks[$whichstock]=$stocks[$whichstock]+$howmany;}; print "\n\nYour Stock Report for January $date\n\n"; print "Company You Own Value\n"; print "DerpCo $stocks[0] \$$derpco\n"; print "Tetrabytz $stocks[1] \$$tetrabytz\n"; print "MojoInc $stocks[2] \$$mojoinc\n"; print "Freke $stocks[3] \$$freke\n"; print "Mega $stocks[4] \$$mega\n"; print " you have \$$cash\n"; print "Would you like to (B)uy or (S)ell? "; $trans=<STDIN>; if ($trans =~/S/i) { print "What Stock would you like to Sell? "; chomp ($sell=<STDIN>); if ($sell =~/derp/i){ print "\nyou have $stocks[0] stocks in DerpCo\n"; print "Sell How many? :"; chomp ($sellnum=<STDIN>); if ($sellnum > $stocks[0] or $sellnum == 0) {print "Nice try\n"} else {$stocks[0]=$stocks[0]-$sellnum; $cash=$sellnum*$derpco;}; }; if ($sell =~/tet/i){ print "\nyou have $stocks[1] stocks in TetraBytz\n"; print "Sell How many? :"; chomp ($sellnum=<STDIN>); if ($sellnum > $stocks[1] or $sellnum == 0) {print "Nice try\n"} else {$stocks[1]=$stocks[1]-$sellnum; $cash=$sellnum*$tetrabytz;}; }; if ($sell =~/Mojo/i){ print "\nyou have $stocks[2] stocks in Mojo Inc\n"; print "Sell How many? :"; chomp ($sellnum=<STDIN>); if ($sellnum > $stocks[2] or $sellnum == 0) {print "Nice try\n"} else {$stocks[2]=$stocks[2]-$sellnum; $cash=$sellnum*$mojoinc;}; }; if ($sell =~/Freke/i){ print "\nyou have $stocks[3] stocks in Freke\n"; print "Sell How many? :"; chomp ($sellnum=<STDIN>); if ($sellnum > $stocks[3] or $sellnum == 0) {print "Nice try\n"} else {$stocks[3]=$stocks[3]-$sellnum; $cash=$sellnum*$freke;}; }; if ($sell =~/Mega/i){ print "\nyou have $stocks[4] stocks in Mega\n"; print "Sell How many? :"; chomp ($sellnum=<STDIN>); if ($sellnum > $stocks[4] or $sellnum == 0) {print "Nice try\n"} else {$stocks[4]=$stocks[4]-$sellnum; $cash=$sellnum*$mega;}; }; }; if ($trans =~/B/i) { print "What Stock would you like to buy? "; chomp ($buy=<STDIN>); if ($buy =~/derp/i){ print "\nyou have $stocks[0] stocks in DerpCo and \$$cash\n"; print "buy How many? :"; chomp ($buynum=<STDIN>); if ($cash < $derpco*$buynum) {print "Not enough cash\n"} else {$stocks[0]=$stocks[0]+$buynum; $cash=$cash-($buynum*$derpco)}; }; if ($buy =~/tet/i){ print "\nyou have $stocks[1] stocks in TetraBytz and \$$cash\n"; print "buy How many? :"; chomp ($buynum=<STDIN>); if ($cash < $tetrabytz*$buynum ) {print "Not enough cash\n"} else {$stocks[1]=$stocks[1]+$buynum; $cash=$cash-($buynum*$tetrabytz)} +; }; if ($buy =~/Mojo/i){ print "\nyou have $stocks[2] stocks in Mojo Inc and \$$cash\n"; print "buy How many? :"; chomp ($buynum=<STDIN>); if ($cash < $mojoinc*$buynum) {print "Not enough cash\n"} else {$stocks[2]=$stocks[2]+$buynum; $cash=$cash-($buynum*$mojoinc)}; }; if ($buy =~/Freke/i){ print "\nyou have $stocks[3] stocks in Freke and \$$cash\n"; print "Buy How many? :"; chomp ($buynum=<STDIN>); if ($cash < $freke*$buynum) {print "Not enough cash\n"} else {$stocks[3]=$stocks[3]+$buynum; $cash=$cash-($buynum*$freke)}; }; if ($buy =~/Mega/i){ print "\nyou have $stocks[4] stocks in Mega and \$$cash\n"; print "buy How many? :"; chomp ($buynum=<STDIN>); if ($cash < $mega*$buynum) {print "Not enough cash\n"} else {$stocks[4]=$stocks[4]+$buynum; $cash=$cash-($buynum*$mega)}; }; }; }; if ($cash > $goal) { $dif = $cash-$goal; print "Yay! you won, you beat your goal by \$$dif\n"; }; if ($cash < $goal) { $dif = $goal-$cash; print "Boo! you lost, you missed your goal by \$$dif\n"; };
Any comments would be appreciated, thank you.

In reply to Seeking Feed Back on a Game by Cobo

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.