lundi 22 mai 2017

if condition too long and including for loop

Hi I am a C++ beginner and here is a problem I am facing when writing a function.

The bool function is Data is used to see whether the array members are all numbers. Usually the size will be 11 or 9 or 7 so I don't want to hard code it. But I am not sure whether for loop work in if condition. And I will be so grateful if you can show me an easier way to do this.

bool isData(string temp[], int size)
{
  if(
      for (int i;i<size;i++) 
      {
        59 > +temp[i].at(0) && +temp[i].at(0) > 47 || +temp[i].at(0) == 45
      }
    )
    {
      return true;
    }
  else 
    {
      return false;
    }
}

Aucun commentaire:

Enregistrer un commentaire