Question

int racer::GoodLapCount() { 
    int s = 0;
    int i = 0;
    while (i < data.size()) {
       if (data[i].laptime < "01:30:000") {
        s++;
        }
    i++;
    }
    return s;
}

Can I disregard the warning 'comparison between signed and unsigned integer expressions' in this case, or does it matter anything here to use it or not ?

Was it helpful?

Solution

I think adat is a vector. Vector returns an unsigned integral type value, you can check this: vector's size()

You can ignore the warning or just use an unsigned int variable to iterate over vector. Or if you strongly need i to be a simple int variable you can roughly cast size to int

while(i < (int)adat.size()) {

but it causes problems if size is over MAX_INT value.

Furthermore, if you are using C++ 11 you can ignore the iterator variable in this way:

for(auto elem : adat) {
   if (elem.korido < "01:30:000") {
    s++;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top