+ 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; }
9 Answers
+ 3
So how do I fix it?
+ 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.
+ 2
No this code does not want cin
+ 2
Thanks non stop .... I was careless I should have written get instead of writing set
+ 2
Thank you for your help:)
+ 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;
+ 1
You need to call getFullname and getAge
https://code.sololearn.com/c8leYpDpIWnX/?ref=app
0
Could it be that you did not cin>> the input variables maybe
0
Mhi tj
Your welcomeđ