I am getting the following errors
25 D:\calculat.cpp expected `(' before "op"
49 D:\calculat.cpp expected `;' before "op"
53 D:\calculat.cpp `y' undeclared (first use this function)
I partly suspect to change it to switch (op) but that gives more errors of the following
27 D:\calculat.cpp expected primary-expression before ':' token
28 D:\calculat.cpp no match for 'operator=' in 'frac3 = CFract::operator+(CFract&)(((CFract&)(&frac2)))'
in each case statement
#include <iostream>
#include <iomanip>
#include <ctype.h>
#include "fraction.h"
using namespace std;
int main()
{
CFract frac1;
CFract frac2;
CFract frac3;
char choice;
char op;
int err;
err = 0;
do
{
cout << "Enter a fraction (a/b), operator(+ - * /), and fraction (c/d),"
"e.g. 1/2 - 1/3: " << endl;
cin >> frac1 >> op >> frac2;
switch (op)
{
case +:
frac3 = frac1 + frac2;
break;
case -:
frac3 = frac1 - frac2;
break;
case *:
frac3 = frac1 * frac2;
break;
case /:
frac3 = frac1 / frac2;
break;
else
err = 1;
}
if(err = 1)
{
cerr << "*** Illegal operator" << endl;
err = 0;
}
else
{
cout << "The result of " << frac1 op frac2 << " is " << frac3 << endl;
}
cout << "Try another (y,n)? " << endl;
cin >> choice;
}while (tolower(choice) = y);
return 0;
}