Expected primary-expressions before 'int' errors
Whenever I try to compile and run the code I get an "expected primary-expression before 'int'" error on lines 9 and 21.
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
|
#include <iostream>
using namespace std;
int array[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
void display_array(int array[]);
void fill_array(int array[]);
int main()
{
cout << "Enter integers to fill the array: ";
fill_array(int array[]);
system("pause");
return 0;
}
void fill_array(int array[])
{
array[10];
for(int i = 0; i < 10; i++)
cin >> array[i];
cout << endl;
display_array(int array[10]);
}
void display_array(int array[])
{
array[10];
for(int i = 0; i < 10; i++)
cout << array[i] << " ";
cout << endl;
}
|
Last edited on
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
#include <iostream>
int array[10] = {}; // initialised to all zeroes
void display_array();
void fill_array();
int main()
{
std::cout << "Enter integers to fill the array: ";
fill_array();
display_array() ;
}
void fill_array()
{
for( int& v : array ) std::cin >> v ;
}
void display_array()
{
for( int v : array ) std::cout << v << ' ' ;
std::cout << '\n' ;
}
|
> fill_array(int array[]);
You only need name the array in question, not all the type information.
Like so
Remove lines 17 and 27 - the ones with just array[10]; on a line.
They're useless out-of-bound accesses.
Topic archived. No new replies allowed.