Why it is not executing ?? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why it is not executing ??

what's wrong here #include <iostream> using namespace std; class series { int n,i,sum; public: int read(); int compute(); int display(); }; int read() { std::cout<<"Enter the value of n:"; cin>>n; } int compute() { for (i=1,sum=0;i<=n;i++) { sum = sum+ i*i; } int display(); { std:: cout<<"value of the series:"<<sum; } }; int main() { series s s.read(); s.compute(); s.display(); return(0); }

10th Mar 2017, 4:06 PM
Ashish Pareek
Ashish Pareek - avatar
3 Answers
0
to declare the bodies of class members, you either declare them in the class itself, or write the function name as "class_name::method_name". eg - instead of writing int read() when you write the body of the method outside the class, write it as int series::read(){ // method body }
10th Mar 2017, 4:42 PM
Nikunj Arora
Nikunj Arora - avatar
0
Dear Ashish, Since you are defining member functions outside the class body, make following corrections in your code and it will work sing namespace std; class series{ int n,i,sum; public: int read(); int compute(); int display(); }; int series :: read(){ std::cout<<"Enter the value of n:"; cin>>n; } int series :: compute(){ for (i=1,sum=0;i<=n;i++){ sum = sum+ i*i; } int series :: display(){ cout<<"value of the series:"<<sum; }
10th Mar 2017, 4:44 PM
देवेंद्र महाजन (Devender)
देवेंद्र महाजन (Devender) - avatar
0
write int series::read () int series::compute() int series::display () use classifier if you are defining function outside of class else if you want to write like this then define functions inside class itself.
10th Mar 2017, 4:46 PM
Raj Kumar Chauhan
Raj Kumar Chauhan - avatar