예제 #1
0
파일: ex_05.cpp 프로젝트: Devtron3D/Books
int main ()
{
	double c = 0;	// declare input variable
	cin >> c;		// retrieve temperature to input variable

	double k = ctok(c);		// retrive result of celsius to kelvin

	cout << k << endl;		// print out temperature

	
	cin >> c;	// retrieve temperature to input variable again.

	double cel = ktoc(c);	// retrive result of kelvin to celsius

	cout << cel << endl;	// print out temperature

	keep_window_open();
}
예제 #2
0
int main(int argc, char* argv[])
{
    if (argc != 3) {

        print_help(argv[0]);
        exit(EXIT_FAILURE);
    }

    char* endptr = NULL;

    errno = 0;
    float temp = strtof(argv[2], &endptr);

    if (errno || *endptr)
        die("Your temperature is not a valid number.");

    puts("Your argument converts to:");
    switch (argv[1][1]) {

    case 'c':
        printf("%.2fK\n", ctok(temp));
        printf("%.2fF\n", ctof(temp));

        break;

    case 'f':
        printf("%.2fC\n", ftoc(temp));
        printf("%.2fK\n", ftok(temp));

        break;

    case 'k':
        printf("%.2fC\n", ktoc(temp));
        printf("%.2fF\n", ktof(temp));

        break;

    default:
        die("Unknown temperature type");
    }

    return EXIT_SUCCESS;
}