Apples

Hello, I've just started my adventure with c++. I found a task: get weight of 10 apples form keyboard and sort it high to low. I did it, but I've got no idea what's wrong. Could you help me? :)
(I work with dev c++)
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
  void sort(int T[], int n)
{
   int k;
   double pom;
   for (int i=0; i<9; i++)
   {
      k=i;
      for (int j=i+1; j<10; j++)
         if (T[j]<T[k]) k=j;
      pom=T[k];
      T[k]=T[i];
      T[i]=pom;
      return T[];
   }  
}
int main() {
	
   int T[];
   int n=10;
   int i;
   
   for (i=0; i<n; i++)
   {
      cout<<"Write weight of apple number "<<i+1<<": ";
      cin>>T[i];
   }
   
   cout<<sort(T[], 10);

	return 0;
}
What error messages are you getting?

How can you print the return value from a function that doesn't return anything?
cout<<sort(T[], 10);

How can you return something from a function that doesn't return anything?

1
2
3
4
  void sort(int T[], int n)
{
     ...
     return T[];


Jim
so there should be something else instead of void, right?
and the error: storage of T isn't known (in sort)
There is a function in algorithm called std::sort you could use with a custom sort like this
std::sort(T , T+10 , [](const int &lhs , const int &rhs ){ return lhs > rhs; };
The custom sort is called a lambda
Last edited on
Topic archived. No new replies allowed.