There's more than one way to do things PerlMonks

### Cycle Gear Ratio Calculator

by fatmac (Acolyte)
 on Sep 04, 2012 at 09:17 UTC ( #991577=CUFP: print w/replies, xml ) Need Help??

With the help of, & grateful thanks to Gangabass, Athanasius, GrandFather, philiprbrenan, & ww. I offer my first proper Perl program to anyone who may like to use it. Cycle Gear Ratio Calculator
#!/usr/bin/perl use strict; use warnings; my \$fh = \*STDIN; # For test input, change to: \*DATA ###my \$fh = \*DATA; # For user input, change to: \*STDIN print "\nMulti Gear Calculator\n\n"; print "Enter Wheelsize (inches): "; my \$wheel = <\$fh>; print \$wheel; chomp \$wheel; print "Enter Chainwheel Teeth: "; my \$chainWheels = <\$fh>; print \$chainWheels; my @chainWheels = split /\s+/, \$chainWheels; print "Enter Cog Teeth: "; my \$cogs = <\$fh>; print \$cogs; my @cogs = split /\s+/, \$cogs; print "Wheelsize: \$wheel\n"; print "Chainwheels: @chainWheels\n"; print "Cogs: @cogs\n\n"; for my \$chainSel (1 .. @chainWheels) { my \$wheelMul = \$wheel * \$chainWheels[\$chainSel - 1]; print "Chain wheel: \$chainSel ratios: \n"; for my \$cogSel (1 .. @cogs) { printf "%5.2f ", \$wheelMul / \$cogs[\$cogSel - 1]; } print "\n"; } __DATA__ 26.5 42 32 22 11 13 15 17 19 21 24 28 32

Replies are listed 'Best First'.
Re: Cycle Gear Ratio Calculator
by davido (Archbishop) on Sep 04, 2012 at 18:06 UTC
That was interesting, especially as they also were reading the same book when they coded it. This is my single gear calculator code:
#!/usr/bin/perl use strict; use warnings; print "\nGear Calculator\n\n"; print "Enter Wheelsize (inches): "; my \$wheel = <>; print "Enter Chainwheel Teeth: "; my \$teeth = <>; print "Enter Cog Teeth: "; my \$cog = <>; my \$gear = \$wheel * \$teeth / \$cog; print "\nYour gear is: ", \$gear, "\n\n";

Create A New User
Node Status?
node history
Node Type: CUFP [id://991577]
Approved by marto
Front-paged by Arunbear
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2017-10-18 02:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
My fridge is mostly full of:

Results (240 votes). Check out past polls.

Notices?