void calculator() { char comm[256]; int i = 1; int c; double total = 0; printf("%f\n", total); while (i) { printf(": "); scanf("%[^\n]%*c", comm); if (comm[1] != '\0') { msg_sender('c'); } else if (comm[0] == 113) { printf("Goodbye!\n"); i = 0; } else if (comm[0] == 104) { msg_sender('h'); } else if (comm[0] == 61) { total = set_value(); printf("%f\n", total); } else if (comm[0] == 43) { total = add(total); printf("%f\n", total); } else if (comm[0] == 45) { total = subtract(total); printf("%f\n", total); } else if (comm[0] == 42) { total = multiply(total); printf("%f\n", total); } else if (comm[0] == 47) { total = divide(total); printf("%f\n", total); } else { msg_sender('c'); } } }
double set_value() { double value; int value_validity; int i = 1; while (i) { printf("= "); value_validity = scanf("%lf", &value); while(getchar()!='\n'){} if (value_validity == 0) { msg_sender('n'); } else { i = 0; } } return value; }
double divide(double total) { double value; int value_validity; int i = 1; while (i) { printf("/ "); value_validity = scanf("%lf", &value); while(getchar()!='\n'){} if (value_validity == 0) { msg_sender('n'); } else { value = total / value; i = 0; } } return value; }
void furnace_send_status() { FurnaceStatus status = furnace_get_status(); msg_sender((const void *)&status, sizeof(FurnaceStatus)); }