im trying to write this function it works almost but if i enter a number in the
ID: 3644088 • Letter: I
Question
im trying to write this function it works almost but if i enter a number in the sorted array its suppose to tell me what number its between for example if i enter 28.5 it should say value not found but between 22 and 29 but only says betwwen 7 and 8 for all high numbers please help if you canvoid findit(double numbers[],int initial_size)
{
int i;
int before;
int after;
double Element;
int endloop;
double min_entry=-100;
double max_entry=100;
double min_value;
double max_value;
min_value=numbers[0];
max_value=numbers[initial_size-1];
char answer;
cout << "do you wish to search for a specific element in the array?"<<endl;
cout << "Type Y for yes and N for no"<<endl;
cin >>answer;
while (answer=='y')
{
cout << "Enter element to search"<<endl;
cin >> Element;
if( Element > max_entry && Element< min_entry)
cout<<"Value exceeds entry range"<<endl;
else if (Element<min_value)
{
cout<< "Value is less than minimum value"<<endl;
cout<< "The minimum value is " << min_value << endl;
}
else if (Element>max_value)
{
cout<<"Element is greater than the maximum value"<<endl;
cout<< "The maximum value is "<< max_value<<endl;
}
else
{
before=0;
after=1;
endloop=0;
while(endloop==0)
{
if(Element==numbers[before]||Element==numbers[after])
{
cout<<"The value is found at element"<<endl;
endloop=1;
}
else if((Element > numbers[before])&& (Element < numbers[after]))
{
cout<< "number not found but between "<< before <<" and "<< after <<endl;
endloop=1;
}
else
{
before=before+1;
after=after+1;
if(before==initial_size)
endloop=1;
}
}
}
}
cin >> answer;
}
Explanation / Answer
Don't forget get to rate me!! Thanks!! #include using namespace std; void findit(double numbers[],int initial_size) { double Element; double min_entry=-100; double max_entry=100; double min_value; double max_value; min_value=numbers[0]; max_value=numbers[initial_size-1]; char answer; coutRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.