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 ?
this is the code:
#include <stdio.h>
#include <iostream>
bool p(int i){if (i==20) return 1;}
int searchfor (int n) {
int i = 0;
for (i=n; i>=p(i); i++)
return i;
}
int searcwhile(int n){
int i=n;
while (!p(i)) {i=i+1; searcwhile(i);};
return i;
}
int SearchFunctional (int n){return(!p(n) ? SearchFunctional (n+1) : n);}
int main()
{
std::cout<<searchfor (7);
std::cout<<searcwhile(8);
std::cout<<SearchFunctional(9);
return 0;
}