0

Idk where I screwed up, someone help plz.

https://code.sololearn.com/cRCEj9489D3z/?ref=app

14th Oct 2018, 1:26 AM
Avi Gluck
Avi Gluck - avatar
10 odpowiedzi
+ 7
We use = for assigning value to the variable. If we are going to perform comparison, use == instead. 😉
14th Oct 2018, 1:46 AM
Zephyr Koo
Zephyr Koo - avatar
+ 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.
14th Oct 2018, 2:08 AM
Jonathan Pizarra (JS Challenger)
Jonathan Pizarra (JS Challenger) - avatar
+ 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.
14th Oct 2018, 1:44 AM
non
+ 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.
14th Oct 2018, 2:18 AM
Jonathan Pizarra (JS Challenger)
Jonathan Pizarra (JS Challenger) - avatar
+ 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.
14th Oct 2018, 2:25 AM
non
0
Zephyr Koo I did tht at first and it didn't work either
14th Oct 2018, 1:47 AM
Avi Gluck
Avi Gluck - avatar
0
nonzyro where r ur comments? I don't see any. Also what r UIDs (I'm not that advanced yet sorry 😌)
14th Oct 2018, 2:04 AM
Avi Gluck
Avi Gluck - avatar
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
14th Oct 2018, 2:11 AM
Avi Gluck
Avi Gluck - avatar
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.
14th Oct 2018, 2:24 AM
Avi Gluck
Avi Gluck - avatar
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.
14th Oct 2018, 2:29 AM
Avi Gluck
Avi Gluck - avatar