I'm trying to write a program where you submit 2 numbers into the executable and use a function to display the addition and subtraction of these 2 numbers.
I know there is a simpler way to do it without using functions, but I'm trying to familiarize myself with classes and stuff. If possible, can anyone help me?
#include <iostream>
usingnamespace std;
class function
{
private:
int x, y;
public:
void set_values(int, int);
int addDisplay() {return (x + y);}
int subDisplay() {return (x - y);}
};
void function::set_values(int a, int b)
{
x = a;
y = b;
}
int main()
{
int c, v;
function mathSolve;
cout << "Enter 2 numbers with a space in between: " << endl;
cin >> c >> v >> endl;
mathSolve.set_values(c, v);
cout << c << " + " << v << "= " << mathSolve.addDisplay() << endl;
cout << c << " - " << v << "= " << mathSolve.subDisplay() << endl;
system("pause");
return 0;
}
Error: Error 1 error C2678: binary '>>' : no operator found which takes a left-hand operand of type 'std::basic_istream<_Elem,_Traits>' (or there is no acceptable conversion) 25