#include <stdio.h>
int UserInput(char* Operation, double* Num){
printf("\nInput Operation: ");
if ( (scanf(" %c", Operation)) != 1 ) {
return 1;
}
printf("\nInput another Number: ");
if ((scanf("%lf", Num)) != 1) {
return 1;
}
return 0;
}
double Arithmetic(double X, double Y, char op){
switch (op){
case '+':
return (X+Y);
case '-':
return (X-Y);
case '/':
return (X/Y);
case '*':
return (X*Y);
}
}
int main(){
int i=0;
int state;
double Result[100], Num[100];
char Operation;
while (1){
printf("Input your Number: ");
scanf("%lf", &Result[0]);
while (1){
state = UserInput(&Operation, &Num[i]);
if (state == 0 && Operation == '-'|| Operation =='+' || Operation =='/' || Operation =='*') {
Result[i+1] = Arithmetic (Result[i], Num[i], Operation);
printf ("\nResult: %.2lf\n", Result[i+1]);
i++;
}else {
printf ("Invalid Operator or Number\n");
}
}
}
return 0;
}