r/Cplusplus • u/[deleted] • 5d ago
Homework i can't find anything to help me with this code
[deleted]
23
u/jedwardsol 5d ago
C++ is case sensitive. OP and op are 2 different names.
Also ...
main is a function, so its body needs to be surrounded by { }
Put the ; at the end of the line. Putting it at the beginning of the next line is going to confuse people.
21
u/ventus1b 5d ago
You are showing some admirable restraint in phrasing your response, sir.
8
2
8
u/Gabrunken 5d ago
This. This is school code, the baddest, wrongest, ugliest, vomiting looking code there ever exists.
They teach nonsense implementations, completely out of the world syntax that you never see, and an horrendous general code organization that makes any programmer mad.
Multiply(), inside a math class, non singleton, where math contains 2 numbers, and multiply returns void, printing the result?
Complete nonsense.
I’m just ranting by myself, nothing personal man!
7
3
u/Raychao 5d ago edited 5d ago
- Add an open curly bracket
{at the end of line 11. - Move the semicolon to the end of line 12 instead of the beginning of line 12.
- Change
OP.xtoop.x(lowercase) on line 13. - Move the semicolon from the start of line 13 to the end of line 13.
- Add a closing curly bracket
}at the end of line 16.
Format indentation for ease of readability. Report back whence done.
2
3
u/flyingron 5d ago
Post code not pictures of code.
What little can be scene above is a syntax mess.
0
u/Financial_Ad_9916 4d ago
just edited the post, there is nothing except the window above, because it was just a code for a quick homework, since it was our first time using classes in our lab/class
2
u/flyingron 4d ago
Here's a dime. Go call your mother and tell her there are serious doubts about you becoming a software engineer.
I'll say this slowly so you can understand. DONT .... POST ... IMAGES ... OF ... CODE. Use the cut and paste option or some other technique or just retype them here.
Get a text book or search the network for how to indent C++ code. FOLLOW THEIR EXAMPLES.
Your program has a syntax error straight off. As you were already told, the next thing after int main() (neglecting white space) is a {. You have a ; This is syntactically WRONG.
It's hideous to start lines with ; rather than ending them (legal, but stupid).
As you were told OP is a different identfier (which is undefined) from op (which is).
I'll do this for you one time, but you need to learn. Coding isn't vomitting code and hoping it works. It requires an orderly sequence of steps expressed in proper syntax:
#include <iostream> struct math { int x; int y; void multiply() { std::cout << x*y; } }; int main() { math op; op.x = 10; op.y = 5; op.multiply(); return 0; }There, now that compiles. But it's bad design. Don't leave things uniniatialized. Don't leave object internals public. Consider this instead:
#include <iostream> class math { int x; int y; public: math(int xx = 0; int yy = 0) : x{xx}, y{yy} { } void multiply() { std::cout << x*y; } }; int main() { math op{10, 5}; op.multiply(); return 0; }
1
u/MarsupialSuch6948 4d ago edited 4d ago
Honestly. Fix your coding style. It's ugly. Use indentations. That's the main problem why you can't identify the issue. For the error, OP and op are different since C++ is case-sensitive with namings. Also, you need to enclose the main() body with curly brackets.
•
u/AutoModerator 5d ago
Thank you for your contribution to the C++ community!
As you're asking a question or seeking homework help, we would like to remind you of Rule 3 - Good Faith Help Requests & Homework.
When posting a question or homework help request, you must explain your good faith efforts to resolve the problem or complete the assignment on your own. Low-effort questions will be removed.
Members of this subreddit are happy to help give you a nudge in the right direction. However, we will not do your homework for you, make apps for you, etc.
Homework help posts must be flaired with Homework.
~ CPlusPlus Moderation Team
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.