What is wrong with my code here?

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

What is wrong with my code here?

Post by answerhappygod »

What is wrong with my code here?
What Is Wrong With My Code Here 1
What Is Wrong With My Code Here 1 (13.41 KiB) Viewed 48 times
What Is Wrong With My Code Here 2
What Is Wrong With My Code Here 2 (65.66 KiB) Viewed 48 times
A Error ./solution.cpp: In function 'int binarySearch(int*, int, int, int)': ./solution.cpp:17:16: error: a function-definition is not allowed here before '{' token int main (void) {
solution.cpp Ⓡ 1 #include<iostream> 2 using namespace std; 3 4 int binarySearch(int A[1000], int p, int r, int num) 5 + { 6 ▾ 23 ▾ 24 7 8 ▾ 9 10 ▾ 11 12 13 14 15 } 16 return -1; 17 int main (void) { 18 int N, num; 19 cin >> N; 20 int A[N]; Y 21 22 - 25 26 27 28 ▾ Y 29 30 31 32 33 34 35 } 36 37 } 38 39 40 if(p <= r) { 11 int mid= (p + r)/2; if(A[mid] == num) return mid; else if(A[mid] > num) return binarySearch(A, p, mid - 1, num); else if(A[mid] < num) return binarySearch(A, mid +1, r, num); for(int i = 0; i < N; i++) { cin >> A } cin >> num; int index = binarySearch (A, 0, N-1, num); if(index == -1) { } else cout << "-1"; cout << index; return 0; Z
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply