Simple calculator program not letting me use the same operator (+.-.*./) twice
I am trying to make a simply calculator that allows the user to continually modify a result using +,-,*, or / , however for some reason my code is only letting me use each operator (+,-,*, or /) one time, before giving me the error message that is supposed to only appear when the user enters a character that is not one of the four basic operators (+,-,*, or /). Actually no matter what I enter the second time it does this. Here is the code. Please help:
Code:
//
// main.c
// calc
//
//
//
#include <stdio.h>
#include <stdlib.h>
#define QUIT 0
#define CONTINUE 1
//---------------math prototype--------------------------
int math (double first, double second, char operator);
int main (void)
{
int equation=CONTINUE;
char operation='+';
double result=10.0, modifier;
printf("calculator is on.\n");
//printf("%d\n",equation);
while (equation==CONTINUE) {
//reading user input of operation and a number:
scanf("%c%lf", &operation, &modifier);
//sending the two values of "result" and "modifier" and the operator character to subfunction called "math"
// and putting the result of "result"(+ or - or * or /)"modifier" in to the variable "result":
result = math(result, modifier, operation);
printf("result=%f\n", result);
}
return 0;
}
//----------math-----------------------------------------------------
int math (double first, double second, char operator)
{
if (operator=='+')
return (first+second);
else if (operator=='-')
return (first-second);
else if (operator=='*')
return (first*second);
else if (operator=='/')
return (first/second);
else
printf("%c is an unknown operation. Reenter your last line:\n", operator);
return (first);
}