/*
 * file :  hw3p2.c
 * ---------------------------
 * Extended version of the prev. problem
 * has four different operators.
 */

#include <stdio.h>
#include <math.h>
#include "simpio.h"

#define TOLERANCE 0.0001

void main()
{
  double num1, num2, result, correctResult;
  char op;
  char another = 'V';

  while(another != 'N'){
    printf("Give me a number: ");
    num1 = GetReal();

    op = 'z';

    while(op != '+' && op != '-' && 
	  op != '/' && op != '*'){
      printf("Give me an operator: ");
      op = getchar();getchar();
      if(op != '+' && op != '-' && 
	 op != '/' && op != '*'){
	printf("unknown operator!\n");
      } /* if */
    } /* while */
    printf("Give me another number: ");
    num2 = GetReal();

    printf("Guess the result: ");
    result = GetReal();
   
    if(op == '+'){
      correctResult = num1 + num2;
    }
    if(op == '-'){
      correctResult = num1 - num2;
    }
    if(op == '/'){
      correctResult = num1 / num2;
    }
    if(op == '*'){
      correctResult = num1 * num2;
    }
    
    
      
    if(fabs (result - correctResult) < TOLERANCE){
      printf("Right!\n");
    }else{
      printf("Wrong!\n");
    }
      
    another = 'V';
    while(another != 'Y' && another != 'N'){
      printf("Another?[y/n] :");
      another = getchar();getchar();
      if (another >= 'a' && another <= 'z'){
        another = another - 'a' + 'A';
      }

    } /* while */
    
  } /* outer while */	   
  printf("okay, bye!\n");
}






