#include <iostream>
#include <conio.h>
usingnamespace std;
void Sorting (int numbers[], int n);
int main()
{
constint MAX_SZ = 1000 ;
int numbers[MAX_SZ] = {0} ;
int n = 0 ;
cout << "enter a serie of numbers, end the input with 0"<< endl ;
int value ;
for( ; n < MAX_SZ && cin >> value && value != 0 ; ++n )
{
numbers[n] = value ;
}
Sorting (numbers, n);
_getch();
return 0;
}
void Sorting (int numbers, int n);
{ // Here pops error: expected a declaration
int slask;
for (int i=0;i<n;i++)
for (int j=(n-1);j>i;j--)
if (numbers[j-1]>numbers[j])
{
slask=numbers[j-1];
numbers[j-1]=numbers[j];
numbers[j]=slask;
}
}
Your function prototype and function implementation signatures don't match. Remember that there is a difference between a pointer (array) parameter and a single instance parameter.
In future please post the complete error message, these messages have important information embedded within them to aid in locating and fixing the problems.
Don't rely on intellinonsense errors, compile your code and then read and post the the actual error messages. The error messages generated by the compiler are usually contain much more information about the errors.
So my Visual C++ kept crushing, and i spent a couple of days strugling to get it back online, nothing. I switched to Dev C++ and finaly got back to this code. And now it stopped working... I think it worked fine, i commented even and in the saved code started making next function, but now it errors me o_O
#include <iostream>
#include <conio.h>
usingnamespace std;
void Sorting (int numbers[], int n);
int main()
{
constint MAX_SZ = 1000 ; // size of the array
int numbers[MAX_SZ] = {0} ;
int n = 0 ; // number of integers entered by the user
cout << "enter a serie of numbers, end the input with 0"<< endl ;
int value ;
for( ; n < MAX_SZ && cin >> value && value != 0 ; ++n ) // extracting and assigning numbers to their positions in the array 'numbers'
{
numbers[n] = value ;
}
Sorting (numbers[], n); //[Error] expected primary-expression before ']' token
_getch();
return 0;
}
void Sorting (int numbers[], int n)
{
int slask;
for (int i=0;i<n;i++)
for (int j=(n-1);j>i;j--)
if (numbers[j-1]>numbers[j])
{
slask=numbers[j-1];
numbers[j-1]=numbers[j];
numbers[j]=slask;
}
}