Error between Switch and For

Sorry if there's anything wrong i'm new on this...
I've spent two days trying to find a solution to this error, and i can't seem to find one; so i have to make a menu with switch and split a bunch of numbers from a TXT file but i get an error.
Here's my code:

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
#include <iostream>
#include <conio.h>
#include "vectores.h"
using namespace std;
main()
{
	int op,n,vecta[10][1],a=0,vectb[10][1],b=0;
	do{
		system("cls");
		cout<<"Ingrese una opcion:\n\n1. Union de A y B.\n2. Interseccion de A y B.\n3. Diferencia de A y B.\n4. Diferencia de B y A.\n5. Diferencia simetrica de A y B.\n6. Determinar la desviacion estandar de cada uno de los conjuntos.\n7. Determinar la desviacion media de cada uno de los conjuntos.\n8. Determinar la moda de los conjuntos.\n9. Determinar la mediana de los conjuntos.\n10. Generar un archivo con todos los resultados.\n11. Salir.  ";
		cin>>op;
		system("cls");
		switch(op)
		{
			case 1:
				cout<<"Opcion 1.\nUnion de A y B";
				getch();
				break;
			case 2:
				cout<<"Opcion 2.\nInterseccion de A y B";
				getch();
				break;
			case 3:
				cout<<"Opcion 3.\nDiferencia de A y B";
				getch();
				break;
			case 4:
				cout<<"Opcion 4.\nDiferencia de B y A";
				getch();
				break;
			case 5:
				cout<<"Opcion 5.\nDiferencia simetrica de A y B";
				getch();
				break;
			case 6:
				cout<<"Opcion 6.\nDesviacion estandar de cada uno de los conjuntos";
				getch();
				break;
			case 7:
				cout<<"Opcion 7.\nDesviacion media de cada uno de los conjuntos";
				getch();
				break;
			case 8:
				cout<<"Opcion 8.\nModa de los conjuntos";
				getch();
				break;
			case 9:
				cout<<"Opcion 9.\nMediana de los conjuntos";
				getch();
				break;
			case 10:
				cout<<"Opcion 10.\nGenerar archivo con los resultados";
				getch();
				break;
			case 11:
				break;	
			default:
				cout<<"Opcion invalida\n";
				system("pause"); 
		}
	  }while(op!=11);
	  getch();
}

and here is the errors im getting from it:

[Error] redefinition of 'int main()'
[Error] 'int main()' previously defined here


Please, i need help i don't know what i've done wrong.
Ps:Sorry for my english...

EDIT

In the include at the begining where it says "vectores.h", it a library i tried to create but can't seem to make it work on the code; anyway, here is the code from de library:

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
#include <iostream>
#include <conio.h>
using namespace std;
main()
{
	FILE *p;
      int n,vecta[10][1],a=0,vectb[10][1],b=0;
      p=fopen("Elementos.txt","r");
      for(int i=1;i<=20;i++)
		{
		fscanf(p,"%d",&n);
			  	if(n==0)
			  	{
					fscanf(p,"%d",&n);
				  	vectb[i][1]=n;
				  }
			  	else
			  	{
					  vecta[i][1]=n;
				}	
		}
		for(int i=1;i<=10;i++)
		{
			cout<<"";
			cout<<" "<<vecta[i][1];
			cout<<"\n";
		}
		system("pause");
		for(int i=1;i<=11;i++)
		{
			cout<<"";
			cout<<" "<<vectb[i][1];
			cout<<"\n";
		}
Last edited on
First off, it should be int main(), as the error suggests.

Second, there can only be one main function.

Third, header files are mainly for declarations, you want to put the definitions in a source file (.cpp).

Plenty of examples here: https://www.google.com/search?q=how+to+use+header+files+C%2B%2B&ie=utf-8&oe=utf-8
So how do i fix it; i mean do i have to change something in the library i tried to create?
also i've puutted int before main as you said, but the error seem to be showing again
two main function
error ->1 in first program and another is "vectores.h" file.

no main in "vectores.h". replace main in vectores.h with a function name for example
void openfile(){......}

then call the function in your first program.

So how do i fix it
I already gave you the answer: https://www.google.com/search?q=how+to+use+header+files+C%2B%2B&ie=utf-8&oe=utf-8

Learn what header files are for, or at least spend a small amount of effort and try to figure it out. What you are trying to do is completely wrong, which you will see by looking at the first result from that link. There is no simple way to change what you have and make it right. I apologize if that sounds harsh, but the link I posted will give you all the answers you need. If there is something you cannot figure out from any of that, then ask a specific question. If you cannot narrow it down more than that, it is too far over your head, and you should concentrate on simpler concepts before moving on, and stick to single file programs for now. I am not trying to discourage you, but you do need to learn how to crawl, before you can walk.
Topic archived. No new replies allowed.