So I've been working on this program for a while, I'm finally finish but I have two error that I can not understand why.
My first error is when I am declaring the header f
//------------------- Mixed.cpp --------------
#include <iostream>
#include "mixed.h"
using namespace std;
ile>
it keep sending me an error message error C2143: syntax error : missing ';' before 'using'
I feel like this is a real simple mistake but I can not figure out what I am doing wrong? There isn't suppose to be a ; before using
my next error is about operator overloading
I wrote overloading function for +,-,/,* and I am getting the same error message for all of them. This is a view of my + function
int Mixed::GCD(int a, int b)
{
int tmp;
while (b)
{
tmp = b;
b = a % b;
a = tmp;
}
return a;
}
Mixed operator+(const Mixed& f1, const Mixed& f2)
{
int newnum, newnum2, gcd, wholeNumber;
double remainder;
Mixed r;
newnum = (f1.integer * f1.denominator) + f1.numerator;
newnum2 = (f2.integer * f2.denominator) + f2.numerator;
r.numerator = (newnum * f2.denominator)+ (newnum2 * f1.denominator);
// load result with the common denominator
r.denominator = f1.denominator * f2.denominator;
gcd = GCD(r.numerator, r.denominator);
r.numerator /= gcd;
r.denominator /= gcd;
wholeNumber = r.numerator / r.denominator;
remainder = (r.numerator % r.denominator);
if (wholeNumber == 0)
cout << remainder << "/" << r.denominator;
else
cout << wholeNumber << " " << remainder << "/" << r.denominator;
return r;
}
My error code is : error C3861: 'GCD': identifier not found, I tried declaring the function GCD before the overload and after the overload function and still same error message
I am not sure if it is my header file that is having teh problem
#include <iostream> // for ostream, istream
using namespace std;
class Mixed
{
friend Mixed operator+(const Mixed& f1, const Mixed& f2);
friend Mixed operator-(const Mixed& f1, const Mixed& f2);
friend Mixed operator*(const Mixed& f1, const Mixed& f2);
friend Mixed operator/(const Mixed& f1, const Mixed& f2);
friend bool operator<(const Mixed& f1, const Mixed& f2);
friend bool operator>(const Mixed& f1, const Mixed& f2);
friend bool operator>=(const Mixed& f1, const Mixed& f2);
friend bool operator<=(const Mixed& f1, const Mixed& f2);
friend bool operator==(const Mixed& f1, const Mixed& f2);
friend bool operator!=(const Mixed& f1, const Mixed& f2);
friend istream& operator>>(istream& out, Mixed& f);
friend ostream& operator<<(ostream& in, Mixed& f);
public:
Mixed(); // Set numerator = 0, denominator = 1.
Mixed(int i, int n, int d); // constructor with parameters
// acts as conversion constructor
void operator++(); // ++ prefix
void operator--(); // -- prefix
void operator++(int); // postfix ++
void operator--(int); // postfix --
double Evaluate();
void ToFraction();
void Simplify();
private:
int integer, numerator, denominator;
double result;
int GCD(int, int);
}