MOD operator not working right...
Hello all.... I am writing a program that will work similar to Matlab (a math program) ... but, I can not get MOD to work right... can some one please explain how to make it work... here is my code...
Code:
#include <iostream>
#include <cmath>
using namespace std;
int getOperand(char ch);
int IsInList(char ch);
char cVar[10];
double dVar[10];
int varNum;
int main ( )
{
char ch;
char op;
int op1;
int op2;
double res;
varNum = 0;
do
{
cout << ">> ";
cin >> ch;
if (ch == 'q')
{
break;
}
op1 = getOperand(ch);
cin >> ch;
if(ch == '=')
{
cin >> dVar[op1];
cout << cVar[op1] << " =\n\n";
cout << " " << dVar[op1] << "\n\n";
}
else
{
op = ch;
cin >> ch;
op2 = getOperand(ch);
switch(op)
{
case '+':
res = dVar[op1] + dVar[op2];
cout << "Ans = \n\n";
cout << " " << res << "\n\n";
break;
case '*':
res = dVar[op1] * dVar[op2];
cout << "Ans = \n\n";
cout << " " << res << "\n\n";
break;
case '/':
res = dVar[op1]/dVar[op2];
cout << "Ans = \n\n";
cout << " " << res << "\n\n";
break;
case '-':
res = dVar[op1] - dVar[op2];
cout << "Ans = \n\n";
cout << " " << res << "\n\n";
break;
case 'mod':
res = MOD(dVar[op1],dVar[op2]);
cout << "Ans = \n\n";
cout << " " << res << "\n\n";
break;
}
}
}
while (1);
}
int getOperand(char ch)
{
int iVar;
iVar = IsInList(ch);
if (iVar == -1)
{
cVar[varNum] = ch;
iVar = varNum;
varNum++;
}
return iVar;
}
int IsInList(char ch)
{
for (int i = 0; i < 10; i++)
{
if(ch == cVar[i])
{
return i;
}
}
return -1;
}
the "case 'mod':" is not working... can someone please review and tell me what i am doing wrong? Thanks.