Simple C++ OOP Question
Hi All members, hope everyone well and happy.
I am having a small problem with C++. I am very new to OOP with C++. The basic idea of this program was to sum all the Odd / even numbers between 1-100 depending on the users choice.
the code goes like this.
Code:
#include<iostream.h>
class cnt
{private:
ch='o';
int x,y;
public:
input()
{ x=0; y=0;
cout<<"Enter Choice:" ;
cin>>ch ;
return ch;
}
sumeven()
{ for(x=0;x<100;x++)
if(x%2==0)
y=y+x ;
return y;
}
sumodd()
{ for(x=0;x<100;x++)
if(x%2>0)
y=y+x ;
return y ;
}
void display()
{ cout<<"Reasult"<<y ;
}
};
void main()
{ cnt ob;
ob.input() ;
if (ch=='o')
ob.sumodd();
else
ob.sumeven() ;
ob.display;
}
On compling i am receiving an error message " for cannot be expanded inline"
I am using turbo c++ for windows.
Please help.
Regards
Amar
Try, Try Hard, Try Harder one day you will Succeed.