i started to learn c++ with only tutorial from the internet and i have this problem when starting to learn about the loops the question was : The function P is total, and as states , has a return value of the type bool, further is only assumed that there are arbitarily larg t , so that p (t) is equal to 1 ,i.e. true. otherwise the particular choice of p does not matter.
all three functions return the first integer t greater than or equal to n to which the property p applies for the argument n . first function use for loop 2nd use while loop the 3rd is SearchFunctional
the SearchWhile and SearchFunctional are returning the value of i=20 but SearchFor is returning i=7 not i=20. how can i make it to return the i=20 ?
There is a problem with function p(). If i is not 20, then the return value is not specified.
Also p() returns a type bool - it it has the value 1 (true) or 0 (false). But in the for loop L8 you are comparing i to be >= p(). As n is 7 in this case, this is always true. The body of the for loop is return i, so the return value is 7!