Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ error: expected primary-expression before ‘int’

I am getting this error for every int in this section of code;

if(choice==2) {
    inssort(int *a, int numLines);
}
if(choice==3) {
    bubblesort(int *a, int numLines);
}
if(choice==4) {
    mergesort(int *a, int numLines);
}
if(choice==5) {
    radixsort(int *a, int numLines);
}
if(choice==6) {
    return 0;
}

Thats where I call the functions in main. If you are wondering I am writing a small program that gives the user a choice when sorting a list between 4 different types of sorting algorithms.

Any help would be appreciated.

like image 396
Will Gunn Avatar asked Nov 14 '11 04:11

Will Gunn


2 Answers

You can't use the declaration types when you're calling the functions. Only when you declare them are they needed:

if(choice==2)
{
    inssort(a, numLines);
}
if(choice==3)
{
    bubblesort(a, numLines);
}
if(choice==4) 
{
    mergesort(a, numLines);
}
if(choice==5) 
{
    radixsort(a, numLines);
}
if(choice==6) 
{
    return 0;
}
like image 169
Mysticial Avatar answered Oct 17 '22 21:10

Mysticial


You're using function declaration syntax to make function calls. That's not necessary, and (as you have discovered) doesn't even work. You can just write

if (choice == 2)
    inssort(a, numLines);
// etc

By the way, a switch would be more idiomatic here.

like image 21
zwol Avatar answered Oct 17 '22 20:10

zwol