
//  for calculating mathmatical expressions 
// by abram on 17/5/2004 Monday 
//calc.cpp 
//  operators was incresed like + = 'p' when u type 2p3 it will be
// _ like 2+3 ..
//if u have comments or icrement code please make it in a .cpp file and put it in
// this fourm 
/////////////////////////////////////////////// TODO : make a calculator by classes //////

#include <iostream.h>

#include <math.h>
int   result;    // the result of the calculations 
char  oper_char; //  operator 
int   value1, value2;     // the 2 values used in equasion 
int main()
{
	cout<< "                 mathmatical calculator  \n"
		<< "                   *** by abram ***   \n";
    result = 0; // initialize the result 
    cout.setf(ios::fixed);
    cout.setf(ios::showpoint);
    // loop forever (or until break reached)
    while (1) {
        cout << "Result: " << result << '\n';
        cout << "Enter a mathmatical expression: ";
        cin >> value1; 
 
        if ((value1 == 'q') || (value1 == 'Q')) // this does not work and will make a loop 
			                                   // forever .. 
            break;

	cin >> oper_char;  
        cin >> value2;
        if (oper_char == '+' || oper_char =='_'||oper_char=='p') { // p means plus
            result = value1 + value2;
        } else if (oper_char == '-' || (oper_char == 's')) { // 's' means substract or mines
            result = value1 - value2;
        } else if (oper_char == '*') {
            result = value1 * value2;
	    }else if (oper_char == '^'){
	    result= pow(value1,value2);
		
          } else if (oper_char == '/') {
            if (value1 == 0) {
                cout << "Error: Divide by zero\n";
                cout << "   operation ignored\n";
	    } else
                result = value1 / value2;
        } 
		  if (oper_char == 'c' ) { // c means cosine 
			  cout<<"we will use the first value * the second value as an angle \n";
			  result=cos(value1*value2);  // treating the two values as an angle 
			  //return (result);
			  // this if statement does not work rightly 
			  // if u have a solution of this problem 
			  // please put it in this file and put it this fourm 
		  }
			
		  else { 
            cout << "Unknown operator " << oper_char << '\n';
        }
    }
    return (0);
}











