### Function does not take 0 arguments error

Hello I am creating a program that uses selection sort, bubble sort, sequential search, and binary search in a menu. I have a Source file, a Header file, and Functions file. Upon compiling I get these four errors.

selectionSort function does not take 0 arguments
bubbbleSort function does not take 0 arguments
sequentialSearch function does not take 0 arguments
binarySearch function does not take 0 arguments

How can I fix this?

sfunctions.cpp
 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105`` ``````#include "Header.h" void showMenu() { cout << "SORT AND SEARCH MENU" << endl << endl; cout << "1. Selection Sort" << endl; cout << "2. Bubble Sort" << endl; cout << "3. Sequential Search" << endl; cout << "4. Binary Search" << endl; cout << "5. Exit" << endl; cout << endl << "Please choose an operation" << endl; } void swap(int* a, int* b) { int temp = *a; *a = *b; *b = temp; } void selectionSort(int array[], int size) { for (int step = 0; step < size - 1; step++) { int min_idx = step; for (int i = step + 1; i < size; i++) { if (array[i] < array[min_idx]) min_idx = i; } swap(&array[min_idx], &array[step]); } } void bubbleSort(int array[], int size) { for (int step = 0; step < (size - 1); ++step) { for (int i = 0; i < size - (step - 1); ++i) { if (array[i] > array[i + 1]) { int temp = array[i]; array[i] = array[i + 1]; array[i + 1] = temp; } } } } int sequentialSearch(int arr[], int n, int x) { int i; for (i = 0; i < n; i++) if (arr[i] == x) return i; return -1; } int binarySearch(int array[], int x, int low, int high) { while (low <= high) { int mid = low + (high - low) / 2; if (array[mid] == x) return mid; if (array[mid] < x) low = mid + 1; else high = mid - 1; } return -1; } void printArray(int array[], int size) { for (int i = 0; i < size; ++i) { cout << " " << array[i]; } cout << "\n"; } int main() { int data[] = { 20, 12, 10, 15, 2 }; int size = sizeof(data) / sizeof(data[0]); selectionSort(data, size); cout << "Sorted array in Acsending Order:\n"; printArray(data, size); int array[] = { 3, 4, 5, 6, 7, 8, 9 }; int x = 4; int n = sizeof(array) / sizeof(array[0]); int result = binarySearch(array, x, 0, n - 1); if (result == -1) printf("Not found"); else printf("Element is found at index %d", result); }``````

Source.cpp
 ``12345678910111213141516171819202122232425`` ``````#include "Header.h" int main() { int choice = 0; do { showMenu(); cin >> choice; switch (choice) { case 1: selectionSort(); case 2: bubbleSort(); case 3: sequentialSearch(); case 4: binarySearch(); case 5: choice = -1; break; } } while (choice >= 0); cout << "Goodbye" << endl; }``````

 ``1234567891011121314`` ``````#pragma once #include #include #include #include #include using namespace std; void showMenu(); void selectionSort(int array[], int size); void bubbleSort(int array[], int size); int sequentialSearch(int arr[], int n, int x); int binarySearch(int array[], int x, int low, int high);``````
Last edited on
 selectionSort function does not take 0 arguments

So `void selectionSort(int array[], int size)`
does not coincide with `selectionSort();`

 How can I fix this?

Well, you could give it the arguments it's pleading for.
So putting (int array[], int size) into the function would fix this issue
 would fix this issue

Probably not - you appear to have int main() in two separate files.
Last edited on
Topic archived. No new replies allowed.