Sorting algorithm

Hello. Im doing this program where you enter a movie collection and then it sorts it by the length of the movies. I get an error that i dont understand at line 41


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
32
33
34
35
36
37
38
39
40
41
#include <iostream>
#include <stdlib.h>

using namespace std;


struct collection {
    string namn;
    string skapare;
    int length;
    };        

void filmsortering(collection info[], int filmer);

int main()
{
    int filmer;

    cout << "Number of movies in your collection: ";
    cin >> filmer;
    cin.ignore(1000, '\n');
    

    collection filmsamling[filmer];
    

    for (int i = 0; i < filmer; i++) {
        cout << "Title of your movie: ";
        getline(cin, filmsamling[i].namn);
        cout << "Director of that movie: ";
        getline(cin, filmsamling[i].skapare);
        cout << "The length of that movie: ";
        cin >> filmsamling[i].length;
        cin.ignore(1000, '\n');
        }
        
  for (int m = filmer-1; m > 0; m--)
  {
         for (int n = 0; n < m; n++)
         {
             if (info[n].length > info[n+1].length)       
             {
                collection temp = info[n];
                info[n] = info[n+1];
                info[n+1] = temp;
                }
             }
                 
    
    cout << "This is your movies of choise: " << endl;
    for (int q = 0; q < filmer; q++)
    {
        cout << left << "\n" << "Film #" << q << "\n" << "Title: " << filmsamling[q].namn << "\n" << "Director: " << filmsamling[q].skapare << "\n" << "Length: " << filmsamling[q].length << endl;
    }
    
    system("PAUSE");
    return 0;

     }
}





Help me ASAP thanks!
Last edited on
I think you meant to put that loop inside filmsortering(), but forgot and left it in main().
Topic archived. No new replies allowed.