Redefinition of int main error

So I have to make programm where user can choose 1 form 3 cases.
I'm this far and it shows error in line 53. - error: redefinition of 'int main()'... Any suggestions why?

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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <iostream>
#include <stdio.h>

using namespace std;

void Bubble1(int array[], int size) {


  for (int step = 0; step < size - 1; ++step) {
    for (int i = 0; i < size - step - 1; ++i) {


      if (array[i] > array[i + 1]) {


        int temp = array[i];
        array[i] = array[i + 1];
        array[i + 1] = temp;
      }
    }
  }
}


void printArray(int array[], int size) {
  for (int i = 0; i < size; ++i) {
    printf("%d ", array[i]);
  }
  printf("\n");
}


int main() {
  int arr[] = {54, 70, 75, 63, 17, 59, 87, 16, 93, 81, 60, 67, 90, 53, 88, 9, 61, 8, 96, 98, 12,
                34, 66, 76, 38, 55, 58, 27, 92, 45, 41, 4, 20, 22, 69, 77, 86, 35, 19, 32, 49, 15,
                29, 23, 83, 95, 25, 91, 33, 47, 24, 62, 13, 42, 73, 44, 78, 72, 7, 5,10, 48, 71, 18,
                39, 97, 64, 79, 51, 74, 31, 37, 57, 30, 94, 80, 28, 1, 56, 85, 46, 100, 82, 40, 26,
                21, 68, 43, 14, 3, 65, 99, 89, 52, 84, 36, 2, 6, 11, 50};

  int size = sizeof(arr) / sizeof(arr[0]);
  Bubble1(arr, size);
  printf(" 1-100 :\n");
  printArray(arr, size);
}


void bubble2 ()
{}

void bubble3 ()
{}

int main ()
{
    int input;

    while(1)
    {
       cout << "Case 1 ";
       cout << "Case 2";
       cout << "Case 3";
       cin >> input;
       switch ( input )
       {
       case 1:
        Bubble1(int array[], int size);
        break;
       case 2:
        Bubble2();
        break;
       case 3:
        Bubble3();
        break;
       default:
        cout << "Error\n";
        break;
       }
    }
}
Last edited on
frog1990 wrote:
So I have to make programm where user can choose 1 form 3 cases.
I'm this far and it shows error in line 53. - error: redefinition of 'int main()'... Any suggestions why?

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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <iostream>
#include <stdio.h>

using namespace std;

void Bubble1(int array[], int size) {


  for (int step = 0; step < size - 1; ++step) {
    for (int i = 0; i < size - step - 1; ++i) {


      if (array[i] > array[i + 1]) {


        int temp = array[i];
        array[i] = array[i + 1];
        array[i + 1] = temp;
      }
    }
  }
}


void printArray(int array[], int size) {
  for (int i = 0; i < size; ++i) {
    printf("%d ", array[i]);
  }
  printf("\n");
}


int main() {
  int arr[] = {54, 70, 75, 63, 17, 59, 87, 16, 93, 81, 60, 67, 90, 53, 88, 9, 61, 8, 96, 98, 12,
                34, 66, 76, 38, 55, 58, 27, 92, 45, 41, 4, 20, 22, 69, 77, 86, 35, 19, 32, 49, 15,
                29, 23, 83, 95, 25, 91, 33, 47, 24, 62, 13, 42, 73, 44, 78, 72, 7, 5,10, 48, 71, 18,
                39, 97, 64, 79, 51, 74, 31, 37, 57, 30, 94, 80, 28, 1, 56, 85, 46, 100, 82, 40, 26,
                21, 68, 43, 14, 3, 65, 99, 89, 52, 84, 36, 2, 6, 11, 50};

  int size = sizeof(arr) / sizeof(arr[0]);
  Bubble1(arr, size);
  printf(" 1-100 :\n");
  printArray(arr, size);
}


void bubble2 ()
{}

void bubble3 ()
{}

int main ()
{
    int input;

    while(1)
    {
       cout << "Case 1 ";
       cout << "Case 2";
       cout << "Case 3";
       cin >> input;
       switch ( input )
       {
       case 1:
        Bubble1();
        break;
       case 2:
        Bubble2();
        break;
       case 3:
        Bubble3();
        break;
       default:
        cout << "Error\n";
        break;
       }
    }
}


At line 33, you define main()

At line 53, you attempt to redefine it.
Topic archived. No new replies allowed.