Ask your own question, for FREE!
Computer Science 14 Online
OpenStudy (gokuporter):

Why do I keep getting a conversion error: char op; cout << "Enter the operator: "; cin >> op; switch (op) { case '+': Square3 = Square1 + Square2; cout << Square3; break; case '-': Square3 = Square1 - Square2; cout << Square3; break; case '*': Square3 = Square1 * Square2; cout << Square3; break; default: cout << "No a valid operator"; }

OpenStudy (karim728):

what error do u get?

OpenStudy (gokuporter):

I get it when I try to cout << Square3 in the switch structure

OpenStudy (gokuporter):

This is what someone else told me The operator << hasn't been defined for a Square object Either define it within the Square class, or cout whatever specific things about Square3 you actually intended

OpenStudy (gokuporter):

Here is the full code http://cpp.sh/3xzz

OpenStudy (gokuporter):

@mathmate

OpenStudy (gokuporter):

@Zale101

OpenStudy (gokuporter):

@Elsa213

563blackghost (563blackghost):

@rishavraj he's good at computer science :)

OpenStudy (mathmate):

@Gokuporter Your post does not mention on which line and which method the error occurred. If it is on one of the cout lines, it would possibly be because you're outputting an object that cout does not know how to convert. Also, the overloaded operators work with the sides of the objects, not the area. I would think it is more intuitive when you add two squares, you would sum the areas. But that's a personal choice. The overloaded * and / will give dimensional problems because side*side gives area units, and side/side will give a pure number, but they both got assigned to the variable "side".

OpenStudy (joshmorris):

hj

OpenStudy (bonnieisflash1.0):

f

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!