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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#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;
}


Header.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#pragma once
#include<iostream>
#include<iomanip>
#include<string>
#include<cstdlib>
#include<time.h>

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.