/*

The C Source for Larry Watanabe's gear chart program

Originally found at ftp://draco.acs.uci.edu/pub/rec.bicycles/gear.c

*/ /* gear.c - prints out a table of gear-inches. * * Example: * * Wheel outside diameter: 27 * * Chainwheel teeth: 50 40 27 * * Rear cog teeth: 13 15 17 19 21 27 * * * 50 40 27 * ------------------------------- * 13 103.85 83.08 56.08 * 15 90.00 72.00 48.60 * 17 79.41 63.53 42.88 * 19 71.05 56.84 38.37 * 21 64.29 51.43 34.71 * 27 50.00 40.00 27.00 * * Larry Watanabe watanabe@cs.uiuc.edu 1994 */ #include #define MAXFRONT 3 /* max number of chainwheels */ #define MAXREAR 8 /* max number of rear cogs */ main() { int c; int i, j; double wheel_diameter; /* outside diameter of wheel */ int front[MAXFRONT]; /* number of teeth for front chainwheels */ int rear[MAXREAR]; /* number of teeth for rear cogs */ int frontn = 0; /* number of front sprockets */ int rearn = 0; /* number of rear sprockets */ double gear_inch; /* gear-inches of current combo */ printf("Wheel outside diameter: "); scanf("%lf", &wheel_diameter); printf("\nChainwheel teeth: "); /* skip over junk to get to a digit */ for (c = getc(stdin); !isdigit(c); c = getc(stdin)) ; ungetc(c, stdin); /* input chainwheel sizes */ for (;;) { c = getc(stdin); if (c == '\n') break; if (isdigit(c)) { ungetc(c, stdin); scanf("%d", &front[frontn++]); } } /* input rear cog sizes */ printf("\nRear cog teeth: "); for (;;) { c = getc(stdin); if (c == '\n') break; if (isdigit(c)) { ungetc(c, stdin); scanf("%d", &rear[rearn++]); } } printf("\n\n "); for (j = 0; j < frontn; j++) printf("\t%4d", front[j]); printf("\n-------------------------------\n"); for (i = 0; i < rearn; i++) { printf("%5d", rear[i]); for (j = 0; j < frontn; j++) { gear_inch = wheel_diameter * front[j]/ rear[i]; printf("\t%3.1lf", gear_inch); } printf("\n"); } }