home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / snip9707.zip / TIRESIZE.C < prev    next >
C/C++ Source or Header  |  1997-07-05  |  3KB  |  88 lines

  1. /* +++Date last modified: 05-Jul-1997 */
  2.  
  3. /*  tiresize.c -  Quick & dirty 'C' program to calculate the actual
  4.  *                dimensions (in English Units) of an automobile tire
  5.  *                given the size specification in the form: 265/75-16
  6.  *
  7.  *                where:  265  is width of tire in millimeters
  8.  *                         75  is ratio of sidewall height to width
  9.  *                             (or aspect ratio)
  10.  *                         16  is the diameter of wheel (rim) in inches
  11.  *
  12.  *                Furthermore, this program will calculate the tire
  13.  *                revolutions per mile driven.
  14.  *
  15.  *        Author: Michael K. Demski
  16.  * Email Address: 75324.3574@compuserve.com
  17.  *          Date: 09/08/96
  18.  *        Notice: Donated to the Public Domain, use at your own risk.
  19.  *   Inspired by: http://www.powerdog.com/tiresize.cgi
  20.  */
  21.  
  22. #include <stdio.h>
  23. #include <stdlib.h>
  24.  
  25. #define MY_PI 3.14159
  26.  
  27. int main(int argc, char *argv[])
  28. {
  29.       float w,    /* tire width in millimeters                        */
  30.             ar,   /* ratio of sidewall height to width (aspect ratio) */
  31.             wd,   /* wheel diameter in inches                         */
  32.             sh,   /* tire sidewall height                             */
  33.             d,    /* total diameter of (wheel + tire)                 */
  34.             c,    /* total circumference                              */
  35.             rev;  /* revolutions per mile                             */
  36.  
  37.       if (4 != argc)
  38.       {
  39.             puts("\nUsage: TIRESIZE <width> <aspect ratio> <diameter>");
  40.             puts("\n       Example:  For a tire of size: 265/75-16\n");
  41.             puts("       Command line:   TIRESIZE 265 75 16\n");
  42.  
  43.             return EXIT_FAILURE;
  44.       }
  45.       else
  46.       {
  47.             w  = atof(argv[1]);
  48.             ar = atof(argv[2]);
  49.             wd = atof(argv[3]);
  50.       }
  51.  
  52.       if (ar > 0.0)                /* ensure no divide by zero error      */
  53.       {
  54.             sh = w * (ar / 100.0); /* tire sidewall height in millimeters */
  55.       }
  56.       else
  57.       {
  58.             puts("Invalid input, please try again.");
  59.             return EXIT_FAILURE;
  60.       }
  61.  
  62.       sh /= (10.0 * 2.54);       /* sidewall height to inches (2.54cm/in) */
  63.       d   = (sh * 2.0) + wd;     /* total diameter of "wheel + tire" (in) */
  64.       c   = 2 * MY_PI * (d / 2.0);      /* total circumference (in)       */
  65.       w  /= (2.54 * 10.0);       /* convert width to inches               */
  66.  
  67.       if (c > 0.0)               /* ensure no divide by zero error        */
  68.       {
  69.             rev = (5280.0 * 12.0) / c;       /* revolutions per mile      */
  70.       }
  71.       else
  72.       {
  73.             puts("Invalid input, please try again.");
  74.             return EXIT_FAILURE;
  75.       }
  76.  
  77.       printf("\n          Tire Width: %7.2f in\n", w);
  78.       printf("     Sidewall Height: %7.2f in\n", sh);
  79.       printf("       Tire Diameter: %7.2f in\n", d);
  80.       printf("       Circumference: %7.2f in\n", c);
  81.       printf("Revolutions per mile: %7.2f\n", rev);
  82.  
  83.       printf("\nA tire: (%s/%.0f-%.0f) is ", argv[1], ar, wd);
  84.       printf("(%.2f) inches tall and (%.2f) inches wide.\n", d, w);
  85.  
  86.       return EXIT_SUCCESS;
  87. }
  88.