Messages - stitched [ switch to compact view ]

Pages: [1] 2next
1
When the IT Dept gets rid of computers they either trash the hard drive and throw them away or give them to a recycling computer company to hipe the HD and resell them.  You should look into it.

2
I have found some amazing deals with off-lease computers.  Ubuntu, Linux Mint or another easy *nix might be suitable for you for these purposes.   :)

3
Living Room / Re: What's your favorite food snack?
« on: March 06, 2009, 07:06 AM »
CH33SYP00FS!!!

4
It works!

Code: C [Select]
  1. /* stitched */
  2.  
  3.  
  4. #include <stdio.h>
  5.  
  6. /* Define Constants to */
  7. /* make error function calls more readable */
  8. #define ERROR_BADWEIGHT     1
  9. #define ERROR_NOT_SELECTION 2
  10.  
  11. /* Define Constants to */
  12. /* make passing logic more understandable */
  13. #define INPUTING_WEIGHT  1
  14. #define INPUTING_PLANET  2
  15. #define END_PROGRAM      3
  16.  
  17. /* Define Function Prototypes */
  18. void moon(double dEarthWeight);
  19. void mars(double dEarthWeight);
  20. void jupiter(double dEarthWeight);
  21. void err_msg(int error);
  22. int exit_program();
  23.  
  24. /* main() function */
  25. int main( void )
  26. {
  27.  
  28.    char cPlanetSelect, cDoMainLoop = 'y';
  29.    int iProcess = INPUTING_WEIGHT;
  30.    double dEarthWeight;
  31.  
  32.    printf("Welcome to ACME Science Center Planetary Weight Computer!\n\n");
  33.  
  34.    do
  35.    {
  36.  
  37.       if ( iProcess == INPUTING_WEIGHT )
  38.       {
  39.  
  40.          printf("Please enter your weight (in pounds on Earth): ");
  41.          scanf("%lf", &dEarthWeight);
  42.  
  43.          if ( dEarthWeight <= -1 )
  44.          {
  45.             err_msg( ERROR_BADWEIGHT );
  46.             continue;
  47.          }
  48.  
  49.          iProcess = INPUTING_PLANET;
  50.          continue;
  51.       }
  52.  
  53.  
  54.       if ( iProcess == INPUTING_PLANET )
  55.       {
  56.  
  57.         printf("Enter the planet ( m for Moon, r for Mars or j for Jupiter): ");
  58.  
  59.         while  ( ( cPlanetSelect = getchar() ) )
  60.          {
  61.  
  62.             switch ( cPlanetSelect )
  63.             {
  64.  
  65.             case 'm':
  66.             case 'M':
  67.  
  68.                moon( dEarthWeight );
  69.                iProcess = exit_program();
  70.             break;
  71.  
  72.             case 'r':
  73.             case 'R':
  74.  
  75.                mars( dEarthWeight );
  76.                iProcess = exit_program();
  77.             break;
  78.  
  79.             case 'j':
  80.             case 'J':
  81.  
  82.                jupiter( dEarthWeight );
  83.                iProcess = exit_program();
  84.             break;
  85.  
  86.             case 'y':
  87.             case 'Y':
  88.                iProcess = INPUTING_WEIGHT;
  89.                break;
  90.  
  91.             case 'n':
  92.             case 'N':
  93.                iProcess = END_PROGRAM;
  94.                return(0);
  95.             break;
  96.  
  97.  
  98.             case '\n':
  99.             case '\t':
  100.             case ' ':
  101.             break;
  102.  
  103.  
  104.             default:
  105.  
  106.             err_msg( ERROR_NOT_SELECTION );
  107.  
  108.             break;
  109.  
  110.            }
  111.  
  112.            if ( iProcess == INPUTING_WEIGHT )
  113.               break;
  114.  
  115.  
  116.         }
  117.       }
  118.  
  119.  
  120.    }
  121.    while ( cDoMainLoop );
  122.  
  123.  
  124.    return(0);
  125. }
  126.  
  127. int exit_program()
  128. {
  129.  
  130.    char cProc = 'Y';
  131.  
  132.    printf("\n\nDo you want to check your weight on a different planet? (Y/N): ");
  133.    cProc = getchar();
  134.  
  135.    if ( cProc == 'Y')
  136.          return (INPUTING_WEIGHT);
  137.    else if
  138.       ( cProc == 'N' )
  139.         return (END_PROGRAM);
  140.  
  141.    return (0);
  142.  
  143. }
  144.  
  145. void moon(double dEarthWeight)
  146. {
  147.    printf("\n\nOn the Moon, you weigh %6.2lf lbs\n", dEarthWeight / 6 );
  148.  
  149.    return;
  150.  
  151. }
  152.  
  153. void mars(double dEarthWeight)
  154. {
  155.    printf("\n\nOn Mars, you weigh %6.2lf lbs\n", dEarthWeight * 0.39 );
  156.  
  157.    return;
  158.  
  159. }
  160.  
  161. void jupiter(double dEarthWeight)
  162. {
  163.    printf("\n\nOn the Jupiter, you weigh %6.2lf lbs\n", dEarthWeight * 2.33 );
  164.  
  165.    return;
  166. }
  167.  
  168. void err_msg(int error)
  169. {
  170.  
  171.  
  172.    if ( error == 1)
  173.             printf("Your weight must be a positive number\n\n");
  174.    else
  175.    {
  176.             printf("\n\nInvalid Selection!\n");
  177.             printf("To Continue Selecting a Planet, Please Type\n");
  178.             printf("( m for Moon, r for Mars, or j for Jupiter): \n");
  179.    }
  180.  
  181.     return;
  182.  
  183. }

5
Thanks for the idea on using #define for constants... I should have known better. :P

I'll post the updates soon.  Never know when you need to know how much your butt weighs on the Moon!  or Uranus...   :P

Pages: [1] 2next
Go to full version