Simple math program help

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?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <iostream>
using namespace 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
The problem is that you try to read into endl:

cin >> c >> v >> endl;
Oh okay, my mistake.
Solved.


THANKS!
Last edited on
Topic archived. No new replies allowed.