I'm pulling in data from a file and putting it into an array. I have that working fine, but from there I'm having issues compiling when I try to run it through a bubble_sort function. Can anyone help find what I'm doing wrong? Thank you!
The specific errors I get are:
demo.cpp: In function ‘int main()’:
demo.cpp:40:9: error: expected primary-expression before ‘]’ token
demo.cpp:40:32: error: expected primary-expression before ‘]’ token
#include <iostream>
usingnamespace std;
int bubble_sort(int scores[]){
int flag = 1;
int temp;
int size = 22;
while(flag != 0){
flag = 0;
for(int x = 0; x < size; x += 1){
if(scores[x] > scores[x + 1]){
temp = scores[x];
scores[x] = scores[x + 1];
scores[x + 1] = temp;
flag = 1;
}
} // end for loop
} // end while loop
} // end bubble function
int main(){
// Setup variables and array
int load_data;
int scores[22];
int x = 0;
// Read data into array
while(!cin.eof()){
cin >> load_data;
scores[x] = load_data;
++x;
}
scores[] = bubble_sort(scores[]);
// Demo output
for(int z = 0; z < 22; z++){
cout << scores[z] << endl;
}
}
I think arrays don't work like that ( At least not to my knowledge I've never attempted ).
Your int bubble_sort also doesn't return a value.
EDIT:
After further observation I think I see what you are trying to do, maybe try passing that array via a pointer/reference along with a size and loop through it to sort it? That way the scoures[] should auto update but heres hoping. :)