-2

I am facing a error when compiling my c++ code, when hovering over it, it says error:- no operator ">=" matches these operands -- operand types are: std::__cxx11::string >= intC/C++(349).

the code goes like this, its a function in a structure, which takes an array variable from the same structure and runs a loop to check the values in that array is greater or equal to 999,

ERROR IS ON THE LINE - if ((PowerChecker.cpower[a] >= 999)) I AM NOT ALLOWED TO COMPARE ARRAY

customers InputChecker(struct customers PowerChecker)
{
    for (int a = 0; a < 4; a++)
    {
        if ((PowerChecker.cpower[a] >= 999))
        {
            cout << "Please re-specify the power of your character" << PowerChecker.cpower[a] << endl;
            cout << "Power shoudl not Excced Limit 999 " <<endl;
        }
        
    }
    return (PowerChecker);
    
}

here is the image of error after compiling Image of error when compiled

EDIT: SOLVED

Abdul raheem
  • 135
  • 2
  • 11
  • 1
    What is cpower? – Raymond Chen Oct 11 '21 at 03:51
  • 3
    Seems like you are comparing a some type of string with an integer. That won't work directly. – drescherjm Oct 11 '21 at 03:57
  • 1
    Apparently `PowerChecker.cpower[a]` is of type `std::string`. `999` is of type `int`. The error message is because a `std::string` and an `int` cannot be compared using a `>=` operator. You've incorrectly assumed that C++ works like some other language you know (e.g. interpret a string like `"123"` as a numeric value, so `"123" >= 999` has the same net effect `123 >= 999`). You need to code to extract an integral value (if present) from the string before comparing. And stop assuming your knowledge of other programming languages is relevant to C++ - C++ and other languages are *different*. – Peter Oct 11 '21 at 04:14
  • Did it not occur to you to share your definition of `customer:::cpowers` with us? – TonyK Oct 11 '21 at 13:43

1 Answers1

1

As Peter and drescherjm wrote in the comments, it seems that you try to compare a string to an integer. You will need to convert the string first. Many ways how to do this can be found here: How can I convert a std::string to int?

SKCoder
  • 409
  • 3
  • 10