Hello,

I am working on an algorithm that checks to see if a value is in an array, however, it doesn't seem to want to work .. It will display that the first number is there but nothing else.. Any ideas? Heres the code:

#include <iostream>
using namespace std;
bool checkNumber(int arr[], int value)
{
	for(int i=0; (i < 10); i++)
	{
		if(value == arr[i])
		{
			return true;	
		}else{
			
			return false;
		}
	}	
}
int main() {
	
	int numbers[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
	
	int value = 2;

	if(checkNumber(numbers, value))
	{
		cout << "Yes";
	
	}else{
		
		cout << "No";
	}
}

Take a look at your braces in your if statement.

Try this

bool checkNumber(int arr[], int value)
{
	for(int i=0; (i < 10); i++)
	{
	  std::cout << arr[i] << std::endl;
		if(value == arr[i])
		{
			return true;	
		}
	}	
	return false;
}
commented: Thank you +2