#include<iostream.h>
#include<conio.h>
class twonum
{
private :
    int x,y;

public:
void getvalues()
{
    cout<<"enter any two numbers";
    cin>>x>>y;
}
void putvalues()
{
    cout<<"\n\n"<<x<<","<<y;
}
int add(int x,int y)
{
    return(x+y);
}
int multiply(int x,int y)
{
    return(x*y);
}
void swap(int x,int y)
{
    int c;
    c=x;
    x=y;
    y=c;
    cout<<x<<","<<y;
};
void main()
{
    clrscr();
    int k,j,l;
    twonum s;
    s.getvalues();
    s.putvalues();
    k=s.add(x,y);
    cout<<"addition:"<<k;
    j=s.multiply(x,y);
    cout<<"multiplication:"<<j;
    s.swap(x,y);
    getch();
}

Regarding conio.h, getch, clrscr, not everyone has conio.h. You might try changing iostream.h to iostream. "void main" should probably be "int main" and your main function should return 0.

Those "problems" might allow it to compile on your machine and not on others, but the actual errors are below.

  1. You are using cout without either the "using namespace std;" line at the top or putting std:: in front of cout.
  2. x and y are data members of your class and they are private too. If x and y were public, your program would compile if you replaced x with s.x and y with s.y However, since they are private, even that won't work.

Whoops, sorry RP, didn't see your post before posting. Good points.

commented: You made good points as well. The code, well, it's just a code dump and run with many dangling unspoken questions. +11

Another thought, it looks to me like you're attempting to use the variables inside the class for your functions. In that case you can leave out the parameters and make the calculations based on the variables inside the class directly. This way they can stay private.

int add()
{
    return(x + y);
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.