Beispiel #1
0
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');
		}
	}
}
Beispiel #2
0
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;
}
Beispiel #3
0
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;
}
Beispiel #4
0
void furnace_send_status() {
    FurnaceStatus status = furnace_get_status();
    msg_sender((const void *)&status, sizeof(FurnaceStatus));
}