Originally Posted by
Matticus
What is your code thus far?
Ok I think I mainly got it. The only thing I don't understand is it will accept a user input with no spaces (such as 5S or 2*) for everything except for the E operator. In that case the user has to format it like 0 E (with a space in between 0 and E). Let me know what you think:
Code:
#include <stdio.h>
int main (void)
{
float number, a;
char operator = 'S';
printf("Begin calculations. \n");
while (operator != 'E')
{
scanf("%f %c", &number, &operator);
switch (operator)
{
case 'S':
a = (number);
printf ("= %f\n", a);
break;
case '+':
a = (a + number);
printf ("= %f\n", a);
break;
case '-':
a = (a - number);
printf ("= %f\n", a);
break;
case '*':
a = (a * number);
printf ("= %f\n", a);
break;
case '/':
if (number == 0)
printf("You can't divide by zero, idiot!\n");
else
a = (a / number);
printf ("= %f\n", a);
break;
case 'E':
printf ("= %f\n End of Calculations.\n", a);
break;
default:
printf ("Unknown operator.\n");
break;
}
}
}