I could use some help!
This is my first course in any sort of coding and I've hit my first major wall, this is with C++ classes. My problem occurs in line 19 of main.cpp:
error C2679: binary '=' : no operator found which takes a right-hand operand of type 'void' (or there is no acceptable conversion)
My problem is as simple as that, I need to find out what's keeping my multipliedBy function from being an applicable operand so I can carry on with my programming!
On a side note, if it is incorrect do not worry about my "result" function, as I'm still in the process of tinkering around with that.
Thank you for your time.
fraction.cpp
#include <iostream>
#include "fraction.h"
using namespace std;
fraction::fraction()
{
top = 0; //default constructor
bottom = 1;
}
fraction::fraction(int numerator, int denominator)
{
top = numerator;
bottom = denominator;
}
void fraction::answer()
{
top = numAnswer;
bottom = denAnswer;
}
void fraction::print() const
{
cout << top << "/" << bottom;
}
void fraction::multipliedBy(fraction f2)
{
numAnswer = top * f2.top;
denAnswer = bottom * f2.bottom;
}
void fraction::result(fraction answer)
{
cout << " is ";
}
fraction.h
#include <iostream>
#ifndef FRACTION_H
#define FRACTION_H
using namespace std;
class fraction {
public:
fraction();
fraction(int numerator, int denominator);
void answer();
void print() const;
void multipliedBy(fraction f2);
void result(fraction answer);
private:
int numerator;
int denominator;
int top;
int bottom;
int numAnswer;
int denAnswer;
};
#endif
main.cpp
#include <iostream>
#include "fraction.h"
using namespace std;
int main()
{
fraction f1(9,8);
fraction f2(2,3);
fraction result;
cout << "The result starts off at ";
result.print();
cout << endl;
cout << "The product of ";
f1.print();
cout << " and ";
f2.print();
result = f1.multipliedBy(f2);
result.print();
cout << endl;
}