Beispiel #1
0
int main(){
	double temperature = 0;		// 気温
	char unit;					// 単位
	double result;

	cout << "気温を入力してください。(c: 摂氏, f: 華氏)" << endl;

	while(cin >> temperature >> unit){
		switch(unit){
			case 'c':
				if(!int_check(ctof(temperature)))
					error("int型で表すことができません。");
				cout << " -> " << (int)ctof(temperature) << "℉" << endl;
				break;
			case 'f':
				if(!int_check(ftoc(temperature)))
					error("int型で表すことができません。");
				cout << " -> " << (int)ftoc(temperature) << "℃" << endl;
				break;
			default:
				cout << "そのような単位は入力できません。" << endl;
				break;
		}		
	}
}
Beispiel #2
0
int main()
{
	try {
		cout << "This program can convert Celsius to Fahrenheit and vice-versa.\n";
		cout << "To convert fahrenheit to celsius type in: 45f or 45c for celsius to fahrenheit.\n";
		double temp;
		string temp_type;
		cin >> temp >> temp_type;

		if (temp_type == "c") {
			double f = ctof(temp);
			cout << "The fahrenheit equivalent of " << temp << " celsius is: " << f << endl;
		}
		else if (temp_type == "f") {
			double c = ftoc(temp);
			cout << "The celsius equivalent of " << temp << " fahrenheit is: " << c << endl;
		}
		else {
			cerr << "Invalid input.\n";
			return 1;
		}
	}
	catch(runtime_error e) {
		cerr << e.what();
	}
	return 0;
}
Beispiel #3
0
int main(void) {
    int i;

    for (i = LOWER; i < UPPER; i = i + STEP)
        printf("%3d\t%6.1f\n", i, ftoc(i));

    return 0;
}
main(){
	int f;
	for(f = 0; f <= 300; f = f + 20){
		float c = ftoc(f);
		printf("%dF = %.1fC\n", f, c);
	}
	return 0;
}
Beispiel #5
0
int main(void)
{
  float fahr;

  for (fahr = 0; fahr <= MAXVAL; fahr += 20)
    printf("%3.0f %6.1f\n", fahr, ftoc(fahr));

  return EXIT_SUCCESS;
}
Beispiel #6
0
main()
{
	int fahr, lower, upper, step;
	lower = 0;
	upper = 300;
	step = 20;
	
	for(fahr = lower; fahr <= upper; fahr = fahr + step)
		printf ("%3d %6.1f\n", fahr, ftoc(fahr));
}
Beispiel #7
0
int main(){
	double lower = 0;
	double upper = 300;
	double step = 20;
	double fahr = lower;
	printf("fahr celsius\n");
	while (fahr <= upper){
		double celsius = ftoc(fahr);
		printf("%3.0f %6.1f\n", fahr, celsius);
		fahr += step;
	}
	return 0;
}
int main()
try
{
	cout << "Enter a temperature and unit of temperature (c = Celsius, f = Fahrenheit)\n";

	double temp_to_convert = 0; //input temperature variable
	cin >> temp_to_convert;
	if (cin.fail()) {
		cin.clear();  //clear cin error flags
		cin.ignore(INT_MAX, '\n'); //clear cin buffer
		error("entered non-numeric temperature!\n");
	}

	char entered_temp_unit = '?';
	cin >> entered_temp_unit;
	entered_temp_unit = tolower(entered_temp_unit);

	double converted_temp = 0;
	char converted_temp_unit = '?';
	switch (entered_temp_unit) {
	case 'f' : 
		converted_temp = ftoc(temp_to_convert);
		converted_temp_unit = 'c';
		break;
	case 'c' : 
		converted_temp = ctof(temp_to_convert);
		converted_temp_unit = 'f';
		break;
	default : 
		error("entered wrong temperature unit of measure!\n");
	}
	cout << "Converted temperature is " << converted_temp << " " << converted_temp_unit << '\n';
	
	keep_window_open();
	return 0;
}
catch (exception& e)
{
	cerr << "error: " << e.what() << '\n';
	keep_window_open();
	return 1;
}
catch (...)
{
	cerr << "Oops: unknown exception!\n";
	keep_window_open();
	return 2;
}
Beispiel #9
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;
}
Beispiel #10
0
/* print Fahrenheit-Celsius table
 * for fahr = 0, 20, ..., 300; floating-point version */
int main()
{
	float fahr, celsius;
	int lower, upper, step;

	lower = 0;
	upper = 300;
	step = 20;

	printf("%4s %7s\n", "Fahr", "Celsius");

	fahr = lower;
	while (fahr <= upper) {
		celsius = ftoc(fahr);
		printf("%4.0f %7.1f\n", fahr, celsius);
		fahr = fahr + step;
	}

	return 0;
}
int main(void)
{
    float fahr, celsius;
    int lower, upper, step;

    lower = 0;      /* lower limit of temperature table */
    upper = 300;    /* upper limit */
    step = 20;      /* step size */

    printf("  F    C  \n");
    printf("----------\n");

    fahr = lower;
    while (fahr <= upper) {
        celsius = ftoc(fahr);
        printf("%3.0f %6.1f\n", fahr, celsius);
        fahr = fahr + step;
    }
    return EXIT_SUCCESS;
}
Beispiel #12
0
int main(void) {
	int tempf = 10;

	int buf[BUF_SIZE] = {0, 0, 0, 0, 0};

	int i, som;

	int sum = 1, go = 1;
	char c;

	int num1, num2;
	int num1t = 0;

	int mul = 0, add = 0, sub = 0, div = 0;

	char text[STRING_SIZE] = "Codenummer = 12345";
	char text2[8] = "abcDEFG";

	printf("%10s %10s\n", "Farenheit", "Celcious");
	fflush(stdout);

	for(; tempf <= 40; tempf += 2){
		printf("%10d %10d\n", tempf, ftoc(tempf));
		fflush(stdout);
	}

	printf("\n");

	for(i = 0; i < BUF_SIZE; i++){
		printf("Please enter a number:");
		fflush(stdout);
		scanf("%d", &buf[i]);
		fflush(stdin);
	}

	printf("\nDe ingevoerde nummers zijn: ");
	fflush(stdout);

	som = 0;
	for(i = 0; i < BUF_SIZE; i++){
		printf("%d ", buf[i]);

		som = som + buf[i];
	}

	printf("de som is: %d\n\n", som);

	printf("de buffer word nu gevuld met de machten van 4\n");
	fflush(stdout);

	for(i = 0; i < 5; i++){
		buf[i] = pow(4, i);
	}

	for(i = 0; i < BUF_SIZE; i++){
		if(buf[i] < 70 && buf[i] > 10){
			printf("%d, de %de macht van 4 is de eerste macht die tussen de 10 en 70 licht\n", buf[i], i);
			fflush(stdout);
			break;
		}
	}

	printf("%s\n", text);
	fflush(stdout);

	int digits = 0;
	for(i = 0; i < STRING_SIZE; i++){
		if(isdigit(text[i])){
			digits++;
		}
	}

	printf("%d\n", digits);
	fflush(stdout);

	for(i = 0; i < 8; i++){
		text2[i] = toupper(text2[i]);
	}

	strcpy(text, text2);

	printf("%s\n\n", text);
	fflush(stdout);

	for(i = 0; i < STRING_SIZE; i++){
		printf("%c, 0x%x\n", text[i], text[i]);
		fflush(stdout);
	}

	printf("\nPlease enter a sum:");
	fflush(stdout);

	while(go){
		while(sum){
			c = getchar();

			switch(c){
				case '+':
					add = 1;
					break;
				case '*':
					mul = 1;
					break;
				case '/':
					div = 1;
					break;
				case '-':
					sub = 1;
					break;
				case 's':
					printf("Programma gestopt");
					fflush(stdout);
					sum = 0;
					return 0;
					break;
				default:
					if(isdigit(c)){
						if(num1t){
							num2 = c - '0';
							sum = 0;
							go = 0;
							break;
						} else {
							num1 = c - '0';
							num1t = 1;
							break;
						}
					} else {
						printf("Error, voer iets anders in");
						fflush(stdout);
						sum = 0;
						break;
					}
			}
		}
		sum = 1;
	}

	fflush(stdin);

	if(add){
		sum = num1 + num2;
	} else if(sub){
		sum = num1 - num2;
	} else if(mul){
		sum = num1*num2;
	} else if(div){
		sum = num1/num2;
	}

	printf("%d\n", sum);
	fflush(stdout);
	return 0;
}