This is the code that is giving me a hard time.

The function is called four times, each changing only the value parameter

Qt Code:
  1. bool ReservedWord::belongsToList(qreal start, qreal end, qreal step, qreal value){
  2. QList<qreal> list;
  3. list << start;
  4. while (list.last() <= end){
  5. list << list.last() + step;
  6. }
  7. list.removeLast();
  8.  
  9. qDebug() << "Checking for" << value << "on list" << list << "and the answer is" << list.contains(value);
  10. return list.contains(value);
  11. }
To copy to clipboard, switch view to plain text mode 

The program output is:

Checking for 4.2 on list (4, 4.2, 4.4, 4.6, 4.8, 5, 5.2, 5.4) and the answer is true
Checking for 4.4 on list (4, 4.2, 4.4, 4.6, 4.8, 5, 5.2, 5.4) and the answer is true
Checking for 4.6 on list (4, 4.2, 4.4, 4.6, 4.8, 5, 5.2, 5.4) and the answer is false
Checking for 5.2 on list (4, 4.2, 4.4, 4.6, 4.8, 5, 5.2, 5.4) and the answer is false

The objective is to define a numbers list by defining it's beginning, it's end and a certain step. Then checking to see if a value belongs to the list. In two cases the value is clearly there but the it is not found.

Any ideas of what is wrong?