cant get the correct return value for calc

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
#include <iostream>
#include <windows.h>

using namespace std;

class addClass{
public:
int add2 (int x,int z)
{
    int ans = x+z;
    cin >> x;
    cin >> z;
     ans = x + z;


    return ans;
}
};



int main()
{
    addClass addOB;
    addOB.add2(0,0);

    system ("Pause");

    return 0;
}



this is the beginning of a multi functional calculator im trying to make as my first multifunctional program. later on im going to try to add if and else if statements to utilize the different calculator types and see what else i can do to make it work.

right now im having trouble getting the value of "ans". I can input 2 numbers but never get a return value. I've tried all that I know, please help me!
return (ans);

That works for me at least.
You do get a return value; but you are just throwing it away. Try:

1
2
// addOB.add2(0,0);
std::cout << addOB.add2(0,0) << '\n' ;
thanks JL, it worked.
Topic archived. No new replies allowed.