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";
}
}
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.