This is the code that is giving me a hard time.
The function is called four times, each changing only the value parameter
bool ReservedWord::belongsToList(qreal start, qreal end, qreal step, qreal value){
QList<qreal> list;
list << start;
while (list.last() <= end){
list << list.last() + step;
}
list.removeLast();
qDebug() << "Checking for" << value << "on list" << list << "and the answer is" << list.contains(value);
return list.contains(value);
}
bool ReservedWord::belongsToList(qreal start, qreal end, qreal step, qreal value){
QList<qreal> list;
list << start;
while (list.last() <= end){
list << list.last() + step;
}
list.removeLast();
qDebug() << "Checking for" << value << "on list" << list << "and the answer is" << list.contains(value);
return list.contains(value);
}
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?
Bookmarks