Solved How to fix my DevC++?

April 23, 2019 at 14:11:55
Specs: Windows 10
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;
}


See More: How to fix my DevC++?

Report •

#1
April 23, 2019 at 15:51:46
✔ Best Answer
Two obvious problems.

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

Using asize before giving it a value. As written, asize should probably be const.

2) cin>>arr[asize];
Storing all inputs to (uninitialized) asize's slot.

How To Ask Questions The Smart Way


Report •
Related Solutions


Ask Question