CCNUAAM

Figure 1. Celsius-to-Fahrenheit conversion
#include <stdio.h>                1 

#include "ccnuaan.h"              2 

void convert(double);             3 

int main(int argc, char **argv)   4 
{
    double c_temp;                5 

    if (argc == 1) {  /* get Celsius value from stdin */

       printf("Enter Celsius temperature: \n");   6 

       if (scanf("%f", &c_temp) != 1) {
          printf("You must enter a valid temperature\n");
       }
       else {
          convert(c_temp);        7 
       }
    }
    else { /* convert the command-line arguments to Fahrenheit */
       int i;

       for (i = 1; i < argc; ++i) {
           if (sscanf(argv[i], "%f", &c_temp) != 1)
              printf("%s is not a valid temperature\n",argv[i]);
           else
              convert(c_temp);    7 
       }
    }
     return 0;
}

void convert(double c_temp) {     8 
   double f_temp = (c_temp * CONV + OFFSET);
   printf("%5.2f Celsius is %5.2f Fahrenheit\n",c_temp, f_temp);
}