This is another question from my study guide for my final exam. If you all could please give me some help.

Write a value returning function called "found" with parameters of a float array a float item and a integer length, that searches the array for any value greater than the value of item. If such a value is found function returns true otherwise returns false. Length is the number of components in the array.

string found(float myarr[], float item, int length);
{
     while (int i=0; i<=(length-1);i++)
     {
          if (myarr[i] > item)
               return "TRUE";
          else
               return "FALSE";
      }
}

You almost have it, what you need to change is :

string found(float myarr[], float item, int length);
{
  //need a for loop not a while
    for(int i=0; i<=(length-1);i++)
    {
          if (myarr[i] > item)
            return "TRUE";
     }
 //will reach here if above does not return true
  return "FALSE";

}

Next time, use code tags.

Thanks for the help. Is there anyway to make it into a while loop?

Thanks for the help. Is there anyway to make it into a while loop?

Sure but why ?

int cntr = 0;

while(cntr < length )
{
  //do code
  cntr++;
}

If you know about boolean types you could consider returning a boolean variable instead of a string variable. At least that's the type I think of when I want/need to return true/false.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.