Arithmetic Operators Help

The Program must allow users to enter any two positive numbers and then display the results.
i'm strugglin plzzz help
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
33
34
35
  #include <iostream>
using namespace std;
class ArithmeticOperators{
private:
    int x;
    int y;
public:
    void set_values();
    int product();
    int difference();
    double quotient();
    int addition();
};
void ArithmeticOperators::set_values(int,int)
cout<<"Enter first value:"<<endl;
cin>>x;
cout<<"Enter second value:";
cin>>y;
product=x*y;
difference=x-y;
quotient=x/y;
addition=x+y;
}
int main{
obj.product()
obj.diffeence()
obj.quotient()
obj.addition
obj.printproduct()
obj.printdifference()
obj.printquotient()
obj.printaddition()
return 0;
}
You have a number of syntax errors in you code (for example you need a pair of parentheses "()" after the main function).

Also in you class declaration set_values has nor arguments but when you define the function it takes two integer parameters. The set_values function should also give the two integer parameters names.

Finally what is this for? The integer class already has a set of operators to use. Normally when creating a class you might overload the operators to be specific to that classes use of the operator. If you need to do this then I would start with sorting out the syntax errors. Then make sure that you have coded all the function for the class. Then in you main function create an instance of the class before using it. You use obj.product() etc but what is obj? the compiler doesnt know about it because you never declare and create an instance of it.

ArithmeticOperators obj;
Topic archived. No new replies allowed.