0
Idk where I screwed up, someone help plz.
10 odpowiedzi
+ 7
We use = for assigning value to the variable. If we are going to perform comparison, use == instead. 😉
+ 4
The problem is that you are comparing the value of w to empty integer variables.
You don't need the int variables. Just compare w to strings like
if(w == "Sword") ... and so on.
Also, it would be more efficient if you use if, if else, and else instead of multiple if statements.
+ 2
I've skimmed over the code and left a comment with some fixes. Main things are "if else" and lack of UIDs for weapons. Good luck.
+ 2
Avi Gluck here's the edited code
https://code.sololearn.com/cLzXoeXqIHtr/?ref=app
I forgot to mention that w should be of string type.
+ 2
Avi Gluck I posted, must've been a bug. Lemme try again:
1. Unique IDs (UIDs): You should use enums for your weapons. You have ints, and they're not initialised so sword == axe is quite possible. Even if you don't use enum (which you should), at least initialise your values.
2. The "if else" speaks for itself. It should be "else if".
3. Regarding #1 & #2, you can use a switch statement instead of if..else if. Same thing but may make life easier for you.
4. Now std::endl terminates a line so you don't need "\n" at the end of each. Or you don't need std::endl (unless you need to flush) and can just use "blah...\n";
BTW, nice catch, Zephyr Koo, I didn't even notice that first if (blah = etc), lol.
0
Zephyr Koo I did tht at first and it didn't work either
0
nonzyro where r ur comments? I don't see any. Also what r UIDs (I'm not that advanced yet sorry 😌)
0
Jonathan Pizarra tx and can u give me an example of using if and else statements cuz the lesson wasn't so clear. tx again
0
Jonathan Pizarra wow tx works like a charm, also I kinda haven't learned abt string type so if u could explain that would be great. tx.
0
nonzyro LMFAO I'll b honest most of that was Chinese to me but tx for all the help I appreciate it, hopefully as I learn more I'll understand what u wrote.