i'm working on a uni project that asks me to create a game, i chose to create an rpg game with heros and each hero has three type of weapon and each type had three specific weapons to use. i've done everything correctly except to limit the selection of the specific weapons since i don't want the user to input numbers, instead i asked him to write the name of weapon, but when i write down if(stringname != "weaponname" || stringname != "weaponname2") it doesn't work. can anyone please help me through this ? and when i ask the user to input his choice (ex : cin >> weappick;) it gives an error: no operator ">>" matches these operands.
I solved the part where it says no operator ">>" matches these operands. but i still can't figure out error:these operands are incompatible (std::string *'' and const char *") a little advice would be appreciated, thanks.
When I look at the bit of code you posted in the if condition and the while condition you are using the logical or. When each side is based on a "!=" the logical and tends to work better. Sometimes the logical or will work, but from what I have seen this is rare.
these operands are incompatible (std::string *'' and const char *")
.
With out knowing how the variables are defined the error message has little meaning other than what it says. Unless the compiler is calling the first parameter a "std::string *" I would guess that you are trying to compare or deal with a "std::string" and either a C style character array or a pointer to a C string. If you could post the code that this error is about and the exact compiler message that would help.
Well My coding is almost 160 lines long and to be honest I don't think you'd want to see that :P, I think i am using a c style character array. to let the user define the string i want, i used
1 2
for(i=0;i<1;i++)
cin >> weappick;
and that worked fine when asking for a name and it worked too on inputting the weapon name, but i can't make a condition to force the user to enter only the weapon's actual name.
Instead of all the drama with trying to match strings, consider using a switch statement with a single char or a number as cases. Also consider the use of enums with the switch as well.