Created
February 19, 2014 15:38
-
-
Save skreuzer/9094558 to your computer and use it in GitHub Desktop.
Temperature Conversion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <unistd.h> | |
#include <math.h> | |
#define C2F(c) c * 9 / 5 + 32 | |
#define F2C(f) (f - 32) * 5 / 9 | |
int | |
main(int argc, char **argv) | |
{ | |
int ch, c_flag = 0, f_flag = 0; | |
float temp; | |
while((ch = getopt(argc, argv, "fct:")) != -1) { | |
switch(ch) { | |
case 't': | |
temp = atof(optarg); | |
break; | |
case 'c': | |
c_flag = 1; | |
break; | |
case 'f': | |
f_flag = 1; | |
break; | |
} | |
} | |
if(c_flag == 1) { | |
printf("%.2fC = %.2fF\n", temp, C2F(temp)); | |
} | |
if(f_flag == 1) { | |
printf("%.2fF = %.2fC\n", temp, F2C(temp)); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment