I wanted to start learning C, and I just got to arguments and they are pretty useful and I decided to write a celsius to fahtrenheit program that took the celsius degree as an arg and typecast it to type long so I could do the calculation. I don't know what's wrong, but I always get a really big negative number. Here is the code:
Code:
1: /**************************************
2: * cels2fahr.c:
3: * A program that takes an integer as an argument
4: * and converts it from Celsius (C) to Fahrenheit
5: * (F).
6: ************************************/
7:
8: #include <stdio.h>
9:
10: int main(int argc, char *argv[]) {
11:
12: int fahr = 0;
13:
14: if (argc < 2) {
15: printf("Proper Usage: \n");
16: printf("cels2fahr <DEGREES IN CELSIUS>\n\n");
17: return 1;
18: }
19:
20: fahr = (9.0/5.0) * (long) argv[1] + 32;
21:
22: printf("%d\n", fahr);
23:
24: return 0;
25: }