I can't delete it

Asked 2 years ago, Updated 2 years ago, 105 views

I modified it because it couldn't be deleted

c++ array function

2022-09-22 18:30

1 Answers

Looking at the code, both if statements are returned.

    for (int i = 0; i < 11; i++){
        if (input.compare(station[i]) == 0){
            return 0;
        }
        else if (input.compare(station[i]) == 1){
            "Cout <<" * Station without. Please re-enter." <<endl;
            return 1;
        }
    }

If you look at this code, i=0, that is, if the comparison statement in the first for statement is 0 or 1, it is written in a structure that returns unconditionally.

The more correct logic would be to return immediately if there is a match to the array, and to return if there is no match to the array (i.e., if you go all the way through the loop).

    for (int i = 0; i < 11; i++){
        if (input.compare(station[i]) == 0){
            return 0;
        }
   }
    "Cout <<" * Station without. Please re-enter." <<endl;
    return 1;


2022-09-22 18:30

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.