I can't find the numbers I want under "before sorting in ascending order"

#include<iostream>

using namespace std;int main()

{

int size, asize;

int arr[asize],min, N, i, j, a[j], low, mid, high, target;

cout<<"Please choose your array size: ";

cin>>size;

cout<<endl;

for(i = 0; i < size; i++)

{

cout<<"Please enter your elements: ";

cin>>arr[asize];

}

cout<<"----before sorting in ascending order------"<<endl;

for( i = 0; i < size; i++)

cout<<"\t"<<arr[i];

cout<<endl;

for(i = 0; i< N - 1; i++)

{

min = i;

for(j = i + 1; j < N; j++){

if (a[j] < a[min])

min = j;

}

swap(a[i], a[min]);

}

cout<<"-----After sorting in ascending order---"<<endl;

for(i=0; i<size; i++)

cout<<"\t"<<arr[i];

cout<<endl<<endl;

cout<<"Please type the elements to search: ";

cin>>target;

low = 0;

high = size-1;

mid;

for(i=0; i<size; i++)

{

mid = (low+high)/2;

if(target==arr[mid])

break;

else if(target<arr[mid])

high = mid-1;

else

low = mid+1;

}

if(target==arr[i])

cout<<"Search Found";

else

cout<<"Search Not Found";

return 0;

}

Two obvious problems. 1)

int size, asize;

int arr[asize],min, N, i, j, a[j], low, mid, high, target;

Usingasizebefore giving it a value. As written,asizeshould probably beconst.2)

cin>>arr[asize];

Storing all inputs to (uninitialized)asize's slot.

Ask Your Question

Weekly Poll

Do you think Intel production shortages are going to help AMD make a comeback?

Discuss in The Lounge

Poll History