Question: This code is supposed to use unseeded rand to generate elements of an array, sort that array in DESCENDING order and have two keys inputted

This code is supposed to use unseeded rand to generate elements of an array, sort that array in DESCENDING order and have two keys inputted , one returns "exists" and one returns "does not exist". I do not understand why my code does not sort the array whatsoever and also, apparently I did not assign any values to the array ( i dont get that). Please correct the code and explain what is wrong with it. Thank you.
Code :
#include
using namespace std;
bool binary_search(int arrayx[], int size, int key);
void selection_sort(int arrayx[], int size);
void printarray(int arrayx[], int size);
int main()
{
int key1;
int key2;
const int size =40;
int arrayx[size];
cout << "Enter key 1"<< endl;
cin >> key1;
printarray(arrayx, size);
selection_sort( arrayx, size);
binary_search(arrayx, size, key1);
cout << "Enter key 2"<< endl;
cin >> key2;
binary_search( arrayx, size, key2);
printarray( arrayx, size);
cout << printarray;
selection_sort(arrayx, size);
cout << selection_sort;
}
void printarray(int arrayx[], int size){
for (int i =0; i < size; i++){
arrayx[i]=30+ rand()%41;
cout << arrayx[i]<<"";
}
}
void selection_sort(int arrayx[], int size)
{
int temp;
for (int i =0; i < size -1; i++)
{
for (int j =i+1; j < size-1; j++)
{
if (arrayx[j]< arrayx[i])
{
temp = arrayx[i];
arrayx[i]= arrayx[j];
arrayx[j]= temp;
}
}
}
}
bool binary_search(int arrayx[], int size, int key){
bool found = false;
int low =0;
int high = size -1;
int middle =(high + low +1)/2;
while ((low <= high) && (found == false))
{
if (arrayx[middle]== key){
found = true;
cout <<"
The key exists.";
}
else
{
if (arrayx[middle]> key)
{
low = middle +1;
}
else
{
high = middle -1;
}
}
middle =(high + low +1)/2;
}
return found;
if (found == false){
cout << "The key does not exist ";
}
else
{
cout << "The key exists";
}
}
bool binary_search(int arrayx[], int size, int key){
bool found = false;
int low =0;
int high = size -1;
int middle =(high + low +1)/2;
while ((low <= high) && (found == false))
{
if (arrayx[middle]== key){found = true;
cout <<"
The key exists.";
}
else
{
if (arrayx[middle]> key)
{
low = middle +1;
}
else
{
high = middle -1;
}
}
middle =(high + low +1)/2;
}
return found;
if (found == false){
cout << "The key does not exist ";
}
else
{
cout << "The key exists";
}
}
*Please disregard brackets and other small syntax errors because the copying messed with the code.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!