expected unqualified-id before ‘{‘
Where is this error on my code? Thanks everyone!
#include <iostream>
using std::cout;
using std::endl;
//function prototypes
void findsmallest (int[], int &);
void findsmallest (int scores [], int & min);
int main()
{
//declare variables
int smallest = 0;
int scores[20] = { 90, 54, 23, 75, 67,
89, 99, 100, 34, 99,
97, 76, 73, 72, 56,
73, 72, 65, 86, 90 };
findsmallest(scores, smallest);
return 0;
//call function find smallest
findsmallest (scores, smallest);
cout << "Minimum value in the array is " << smallest << endl;
system ("pause");
return 0;
}
//function definition
void findsmallest(int scores [], int & min);
{
min = scores[0];
int i;
for(i = 0; i < 20; i++)
{
if(scores[i] < min)
{
min = scores[i];
}
}
}
//end display findsmallest
system ("pause");
return 0;
The error is in the first line of the
findsmallest()function definition. Get rid of the semicolon and it should work (barring other errors in the code — I didn’t check it for correctness).vs
The error is telling you that the open brace (
{) that follows the semicolon is lacking a preceding class/struct/union/function declaration, so the compiler doesn’t know what to do with it. Remove the semicolon and now the compiler knows that it’s the body of a function definition.