0
bool check_valid_key (string s)

{
    for (int i = 0, len = strlen(s); i < len; i++)
    {
    if (!isdigit(s[1]))
    
        return false;
      
    return true;
    
    }
}
0

If s = "" (the empty string), then the for loop will never run. There's no return statement outside the for loop, so you'll reach the end of the function. However, the return type of the function is bool, which means you're promising to return a bool value. Think about where exactly the return statements should be, and make sure you can never reach the end of the function without returning something.

Also, I added the code format marks (three backticks before and after the whole code) to make your post easier to read, but it looks like you're also missing a }, since there's nothing in between the return false; and return true; statements.

1
  • Think about it more. If the for loop doesn't run, should the function return true or false?
    – Cliff B
    Jul 28 '20 at 21:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .