0

Need Help with Encapsulation Assignment.

When running my code, I keep getting No Output. Tried tinkering with the code for a while but couldn't come up with a fix. #include <iostream> using namespace std; //class definition class Car{ //private area private: int horsepowers; //public area public: //complete the setter function void setHorsepowers(int x) { horsepowers = x; } //complete the getter function int getHorsepowers() { return horsepowers; } }; int main() { //getting input int horsepowers; cin >> horsepowers; //creating the object of class Car Car car; //setting the value for private member car.setHorsepowers(horsepowers); //printing the value of private member if (car.getHorsepowers() > 800){ cout << "Too much" << endl; } else cout << car.getHorsepowers(); return 0; }

27th May 2021, 3:24 AM
Xiveski
Xiveski - avatar
5 Respostas
+ 1
Xiveski I think it might be a new SoloLearn bug. The codes are showing No output when you run them. I don't know since how long this happening, but I experienced it today for the first time. Repeatedly trying to run the code works. It shows No output sometimes, but it does run the other times. I have tried running your code and it works fine. Try running the code repeatedly till you get the output.
27th May 2021, 4:24 AM
XXX
XXX - avatar
+ 2
You forgot the closing curly bracket } for the main function body, after the return statement. (Edit) Code in Description had been edited.
27th May 2021, 3:32 AM
Ipang
+ 1
@Ipang My bad! I failed to copy the last bit into my question. However, my code doesn't work as intended. No Output.
27th May 2021, 3:43 AM
Xiveski
Xiveski - avatar
+ 1
Okay, can you save the code in SoloLearn and share the link to it instead? Follow this guide in case you didn't know how ... https://www.sololearn.com/post/75089/?ref=app
27th May 2021, 3:48 AM
Ipang
+ 1
XXX Thank you! I was spending way more time than I was expecting with this question. I ran the code a few times and got it to work.
27th May 2021, 10:18 AM
Xiveski
Xiveski - avatar