Clear code error | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Clear code error

#include <iostream> using namespace std; class addition public : { Void add (int a,int b,int c) { c=a+b; } }; public subtract :public addition; { Void sub (int d,int e) { e=c-d; } }; int main() { subtn.s; s.add ; s.sub; cout <<"enter the add: "; cin >>a+b; cout <<"the value of add "<<c; cout <<"enter the sub: "; cin >>d; cout <<"the value of sub "<<e; return 0; }

17th Dec 2016, 11:40 AM
Hariharan.g
Hariharan.g - avatar
3 Answers
+ 1
// Probably you need something like that: #include <iostream> using namespace std; class Addition { public: int c; int add (int a,int b) { return a+b; } }; class Subtract : public Addition { public: int sub(int d) { return c-d; } }; int main() { Subtract s; int a,b,d; cout <<"enter the add: "; cin >> a; cin >> b; cout << a << " + " << b << endl; s.c = s.add(a,b); cout <<"the value of add "<< s.c << endl; cout <<"enter the sub: "; cin >> d; cout << "you entered sub: " << d << endl; cout <<"the value of sub "<< s.sub(d) << endl; return 0; }
19th Dec 2016, 9:13 PM
Anna Papachristou
Anna Papachristou - avatar
0
where you denote C
20th Dec 2016, 10:09 AM
Hariharan.g
Hariharan.g - avatar
0
It is a field in class Addition
20th Dec 2016, 4:38 PM
Anna Papachristou
Anna Papachristou - avatar