Thanks for the advice but I had just realized myself about the mistake with the (y == '0') line. I've rewritten it and while I think I understand the do while statement I must be missing something. Perhaps someone could tell me whats wrong with the code as it is written now. It still brings up an 'Encountered an error must close' dialog as it executes. ......thks
Code:
int main()
{
FILE* infile;
FILE* outfile;
int x, y, answer;
char op;
infile = fopen("calc4.in", "r");
outfile = fopen("calc4.out", "w");
do
{
fscanf(infile, "%d %c %d", &x, &op, &y);
if (op == '+')
answer = x + y;
else
if (op == '-')
answer = x - y;
else
if (op == '*')
answer = x * y;
else
if (op == '/')
answer = x / y;
else
fprintf(outfile, "\nIllegal Operator.");
if (y == 0)
fprintf(outfile, "\nDivision by zero not allowed!");
else
fprintf(outfile, "\n%d%c%d = %d", x, op, y, answer);
}
while (!((x == 0) && (y == 0)));
return 0;
}