Compilation failed due to following error(s). main.cpp: In function 'int main()':
main.cpp:49:20: error: invalid conversion from 'int*' to 'int' [-fpermissive]
showArray(array, x);
^
main.cpp:16:6: note: initializing argument 1 of 'void showArray(int, int)'
void showArray(const int, int);
^
main.cpp:51:21: error: invalid conversion from 'int*' to 'int' [-fpermissive]
selectSort(array, n);
^
main.cpp:14:6: note: initializing argument 1 of 'void selectSort(int, int)'
void selectSort(int, int);
^
main.cpp:54:20: error: invalid conversion from 'int*' to 'int' [-fpermissive]
showArray(array, x);
^
main.cpp:16:6: note: initializing argument 1 of 'void showArray(int, int)'
void showArray(const int, int);
^
main.cpp:56:40: error: invalid conversion from 'int*' to 'int' [-fpermissive]
int results = binarySearch(array, x, n);
^
main.cpp:13:5: note: initializing argument 1 of 'int binarySearch(int, int, int)'
int binarySearch(const int, int, int);
I get these errors, I'm unsure what I did wrong? Any help would be greatly appreciated.
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 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
|
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int binarySearch(const int, int, int);
void selectSort(int, int);
int median(int, int);
void showArray(const int, int);
const int x = 50;
int main()
{
int n;
int array[x];
string myfile;
ifstream testfile;
cout << "Enter file name: ";
cin >> myfile;
testfile.open(myfile.c_str());
if (!testfile)
{
cout << "Error opening file\n";
cin.get();
return -1;
}
else
{
testfile >> n;
int array[n];
for (int i = 0; i < 50; i ++)
testfile >> array[i];
}
testfile.close();
cin.get();
return 0;
cout << "The unsorted values are: \n";
showArray(array, x);
selectSort(array, n);
cout << "The sorted values are: \n";
showArray(array, x);
int results = binarySearch(array, x, n);
if (results == -1)
cout << "That number does not exist in the array." << endl;
else
{
cout << "That number is found at element " << results;
cout << " in the array." << endl;
}
int median1;
median1 = median ( array[0], x);
cout << endl << median1;
return 0;
}
void selectSort(int array[], int n)
{
int pos_min,temp;
for (int i=0; i < n-1; i++)
{
pos_min = i;
for (int j=i+1; j < n; j++)
{
if (array[j] < array[pos_min])
pos_min=j;
}
if (pos_min != i)
{
temp = array[i];
array[i] = array[pos_min];
array[pos_min] = temp;
}
}
}
int binarySearch(const int array[], int x, int value)
{
int first = 0;
int last = x-1;
int middle;
int position = -1;
bool found = false;
while(!found && (first <= last))
{
middle = (first+last)/2;
if (array[middle] == value)
{
found = true;
position = middle;
}
else if (array[middle] > value)
last = middle -1;
else
first = middle+1;
}
return position;
}
int median(int array[], int x)
{
if (x % 2 == 0)
return (array[x / 2] + array[x / 2 - 1]) / 2;
else
return array[x / 2];
}
void showArray(const int array[], int x)
{
for (int count = 0; count < x; count++)
cout << array [count] << " " ;
cout << endl;
}
|