+ 4

Code error

Why does this code not run? What's wrong? #include<iostream> #include<string> using namespace std; class student { private: string Fullname; int Age; //int avgg; //string id; public: void setFullname(string str){Fullname=str;} string getFullname(){return Fullname;} void setAge(int i){Age= i;} int getAge(){return Age;} }; int main() { student abj; abj.setFullname("mahdiye"); abj.setAge(22); cout <<"fullname:"<<abj.setFullname() <<endl << "age:"<<abj.setAge()<<endl; return 0; }

1st Mar 2022, 4:05 PM
Mhdis
Mhdis - avatar
9 Answers
+ 3
So how do I fix it?
1st Mar 2022, 4:22 PM
Mhdis
Mhdis - avatar
+ 2
I think you meant to call the getters obj.getFullname() and obj.getAge() rather than the setters setFullname() and setAge() when you print outputs.
1st Mar 2022, 4:12 PM
Ipang
+ 2
No this code does not want cin
1st Mar 2022, 4:22 PM
Mhdis
Mhdis - avatar
+ 2
Thanks non stop .... I was careless I should have written get instead of writing set
1st Mar 2022, 4:50 PM
Mhdis
Mhdis - avatar
+ 2
Thank you for your help:)
1st Mar 2022, 4:51 PM
Mhdis
Mhdis - avatar
+ 1
Simply replace abj.setFullname() with abj.getFullname() and abj.setAge() with abj.getAge(). In the line where you print outputs cout << "Fullname: " << abj.getFullname() << endl << "Age: " << abj.getAge() << endl;
1st Mar 2022, 4:28 PM
Ipang
+ 1
You need to call getFullname and getAge https://code.sololearn.com/c8leYpDpIWnX/?ref=app
1st Mar 2022, 4:29 PM
NonStop CODING
NonStop CODING - avatar
0
Could it be that you did not cin>> the input variables maybe
1st Mar 2022, 4:19 PM
Grace Nyutu
Grace Nyutu - avatar
0
Mhi tj Your welcome👍
1st Mar 2022, 4:53 PM
NonStop CODING
NonStop CODING - avatar