arrays ascending & descending

I dont know what i did wrong an error keeps popping up.


#include <iostream>
using namespace std;
class project {

private:
int nums[];


void choiceDescending() {
int temp;
int arraySize = sizeof(nums[0]);
for (int i = 0; i < arraySize-1; i++) {
for (int j = (i+1); j < arraySize; j++) {
if (nums[i] < nums[j]) {
temp = nums[i];
nums[i] = nums[j];
nums[j] = temp;
}
}
}
}

void choiceAscending() {
int temp;
int arraySize = sizeof(nums[0]);
for (int i = 0; i < arraySize; i++) {
for (int j = (i+1); j < arraySize; j++) {
if (nums[i] > nums[j]) {
temp = nums[i];
nums[i] = nums[j];
nums[j] = temp;
}
}
}
}

int main(int nums[]) {

int index;
cout << "Enter how many numbers in your list (5-10): "<<endl;
cin >> index;

// Array setup

nums[index];
cout << "Enter your number.";

int temp;
for (int i = 0; i < index; i++) {
cout << "Number " << i << ": " <<endl;
cin >> temp;
nums[i] = temp;
}

int choice;
cout << "Sort your list in which way? (1 = Ascending 2 = Descending)"<<endl;
cin >> choice;

if (choice == 1) {
void choiceAscending();

}
else if (choice == 2) {
void choiceDescending();

}
else {
cout << "Error. Improper choice."<<endl;
}


}



};
I dont know what i did wrong an error keeps popping up.

Normally it's helpful if you supply us with the error that keeps popping up.


1
2
3
4
class project {

private:
    int nums[];  // <- This is illegal.  You must provide a size that is a compile-time constant.  


It keeps saying 'control reaches end of non-void function'
Hi,

Just some tips for the future, as well as now :+)

If you have compiler errors, post them verbatim. We would like to see all of the actual error, not part of it, or in the worst case someone's own interpretation of the error.

Please always use code tags:

http://www.cplusplus.com/articles/z13hAqkS/


The very last line of your code has a semicolon after the brace - that is supposed to go at the end of the class definition, so it's possible that main and everything is trying to be inside your class.

Edit: It may be that brace with the semicolon is an extra one, anyway make sure there is a semicolon at the end of the class - it's important.

Consider putting the class definition in it's own header file. Name the file exactly the same as the class name. I like to use an extension of .hpp because that means it contains c++ code.

Also put the class function definitions into their own .cpp file, also named exactly after the class name. Have a read on Google on other things to keep not of when doing this.

Good Luck !!
Last edited on
It keeps saying 'control reaches end of non-void function'


You have a function called main as a member of your project class which promises to return an int. It does not. Don't promise to return something if you're not going to return something.

Are you coming from Java? In C++ we tend to avoid member methods named main, but we need a non-member function main as the entry point to the program.
Topic archived. No new replies allowed.