Last night, I was doing the exercises in Chapter 2 of The Llama Book and decided to try some "extra credit" coding when I came up with this idea. I used to do a lot of bicycling when I was in college and currently looking to buying a recumbent. With anywhere from 24 to 27 speeds, it's nice to know what the gear inches are for each speed. A gear inch, by the way, is a calculation based on the gear ratios and the size of the drive wheel. It described how "big" your drive wheel is (and in this case bigger means faster). I am hoping to modify the code later to give the entire range of gears, but that's for Chapter 3. ;)
Thoughts, opinions, hints, etc. gladly welcomed.
Frog
#!/usr/bin/perl -w
print "Enter the number of teeth on the chainring: ";
chomp ($chainring = <STDIN>);
print "Enter the number of teeth on the cog: ";
chomp ($cog = <STDIN>);
if ($cog <= 0) {
print "Error: The gear inches cannot be calculated using $cog as a c
+og value. Please enter another value.";
} else {
print "Is your rear wheel metric? (y/n): ";
chomp ($_ = <STDIN>);
if ($_ eq "y") {
print "Enter your metric wheel size in millimeters: ";
chomp ($metric = <STDIN>);
$wheel = $metric * .039;
$gear_inches = ($chainring / $cog) * $wheel;
print "The gear inches for a chainring of $chainring teeth and a c
+og of $cog teeth and a wheel of $metric millimeters is $gear_inches g
+ear inches.\n";
} else {
print "Enter your wheel size in inches: ";
chomp ($wheel = <STDIN>);
$gear_inches = ($chainring / $cog) * $wheel;
print "The gear inches for a chainring of $chainring teeth and a c
+og of $cog teeth for a wheel $wheel inches in diameter is $gear_inche
+s gear inches.\n";
}
}