### << Operand problems

I am working on a much more complex program than I am used to and I have no idea why << in my cout statement, and < in a if statement will not work. Any advice on the program overall will be helpful also! Thanks!
 ``12345678910111213141516171819`` ``````#include "151fraction.h" #include using namespace std; int main(){ Fraction one(1,2); Fraction two(2,3); (one.print()) ; Fraction product = one.multiply(two); product.print(); Fraction added =one.add(two); added.print(); Fraction subtracted = one.subtract(two); subtracted.print(); Fraction divided = one.divide(two); cout<< "When the fractions are divided the answer is: " << divided.print() << endl; return 0; }``````

 ``1234567891011121314151617181920212223242526`` ``````/* * * Stubbed Fraction Class Header File */ class Fraction{ private: int numerator; int denominator; public: Fraction(int num = 0,int denom = 1); Fraction add(const Fraction&) const; Fraction subtract(const Fraction&) const; Fraction multiply(const Fraction&) const; Fraction divide(const Fraction&) const; void read() const; void print() const; void reduce(); bool isSmaller(Fraction &f) const; }; ``````

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475`` ``````/* * * Stubbed Fraction Class .CPP File */ #include "151fraction.h" #include using namespace std; // Constructor Fraction::Fraction(int num, int denom){ numerator = num; denominator = denom; } // Addition Method Fraction Fraction::add(const Fraction &variable) const{ Fraction added; added.numerator = ((numerator * variable.denominator) + (variable.numerator * denominator)); added.denominator = (denominator * variable.denominator); return added; } //Subtraction Method Fraction Fraction::subtract(const Fraction &var) const{ Fraction subtracted; subtracted.numerator = ((numerator * var.denominator) + (var.numerator * denominator)); subtracted.denominator = (denominator * var.denominator); return subtracted;; } //Multiplication Method Fraction Fraction::multiply(const Fraction &multiplier) const{ Fraction product; product.numerator = numerator * multiplier.numerator; product.denominator = denominator * multiplier.denominator; return product; } //Division Method Fraction Fraction::divide(const Fraction &divisor) const{ Fraction quotient; int temp = divisor.numerator; int newdenom = divisor.numerator; int newnum = divisor.denominator; quotient.numerator = numerator * newnum; quotient.denominator = denominator * newdenom; return quotient; } // Reading Method void Fraction::read() const{ } //Display Method void Fraction::print() const{ cout << numerator << "/" << denominator << endl; } //Reduce Method void Fraction::reduce(){ } //Comparison Method bool Fraction::isSmaller(Fraction &f)const{ if( (((double)numerator)/denominator)) < (((double)f.numerator)/f.denominator))){ return true;}; } ``````
There is no use to pass void to cout. Just place divided.print() routine in their own statement.
As for if, your parenthesises in condition aren't balanced. just remove them all and olace where needed.
line 71 and 30: redundant semicolons
Last edited on
Topic archived. No new replies allowed.