Array

I cant run my program i dont know the problem.
someone help me fix it thanks

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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
 #include<iostream>
using namespace std;
 void insertion(int a,[n]);
int main();
{ 

int i, x, pos=0,n;
cout<<"Enter"<<n<<" numbers in ascending position: ";
    		for(i=0;i<n;++i)
        		cin>>a[i];
    			cout<<"\nEnter element to insert:";
    			cin>>x;
    
   			 for(i=0;i<n;++i)
       			 if(a[i]<=x&&x<a[i+1])
       			 {
            		pos=i+1;
           			 break;
       			 }
        
    		for(i=n+1;i>pos;--i)
       			 a[i]=a[i-1];
    				a[pos]=x;
    				cout<<"\n\nArray after inserting element:\n";
    
    		for(i=0;i<n+1;i++)
        		cout<<a[i]<<" ";
}
void deletion(int a[n])
{
int i, key;
cout<<"Enter"<<n<<" numbers: ";
   			for(i=0;i<n;i++)
   			{
    			cin>>a[i];
   			}
   		cout<<"\n\nStored Data in array:  ";
   			for(i=0;i<n;i++)
   			{
    			cout<<a[i]<<" ";
   			}
   		cout<<"\n\nEnter poss. of element to delete: ";
   		cin>>pos;
  			if(pos>n)
  			 {
   				cout<<"\n\nThis value is out of range: ";
  			 }
  			else
   				{
   					--pos;
   					for(i=pos;i<=n-1;i++)
   					{
   						 a[i]=a[i+1];
  					 }
   		cout<<"\n\nNew data in array: ";
   			for(i=0;i<n-1;i++)
		   {
		    cout<<a[i]<<" ";
 			}
 				 }
}
void searching(int a[n])
{
   cout<<"Enter"<<n<<" numbers: ";
    	for(int i = 0; i < n; i++){
        	cin>>a[i];
   		 }
    	cout<<"Enter the value to search: ";
    	cin>>key;
    	for(int i=0;i<n;i++){
        	if(key == a[i]){
           	 no = true;
            	cout<<"The value is found at index arr["<<i<<"]";
       	 		}
   	 		}
   	 if(!no){
     	   cout<<"Key not found!";
   	 } 
}
void sorting(int a[n])
{
    int i,j,hold;
cout<<"Enter "<<n <<"numbers: "<<endl;
		for(int i=0; i<n; i++)
		{
			cin>>a[i]; 
			} 
			cout<<endl; 
			cout<<"Orignally entered array by the user is: "<<endl;
		for(int j=0; j<n; j++)
		{
			cout<<a[j];
			cout<<endl; 
		} 
			cout<<endl;
		for(int i=0; i<n-1; i++)
			{
				for(int j=0; j<n-1; j++)
				{
					if(a[j]>a[j+1])
						{
							hold=a[j];
							a[j]=a[j+1];
							a[j+1]=hold; 
						}
				}	 
			} 
		cout<<"Sorted Array is: "<<endl;
			for(int i=0; i<n; i++)
			{
				cout<<a[i]<<endl; 
			}
}
int main()
{
	
    int a[],n,x,i,pos=0,cho,no, key , hold;
    
    cout<<"Menu"<<endl;
    cout<<"[1] Insertion"<<endl;
    cout<<"[2] Deletion"<<endl;
    cout<<"[3] serching"<<endl;
    cout<<"[4] sorting"<<endl;
    cout<<"Enter size of array:";
    cin>>n;
    cout<<"Enter choice";
    cin>>cho;
    switch(cho)
    {
    	
	case 1:
    	insertion(a[n]);
    break;
    
    case 2:
        deletion(a[n]);
 	 break;
  case 3:
  	void serching(a[n]);
    break;
  		
	case 4:
		 void sorting (a[n]);
		break;
		
		default:
			cout<<"FAULT!!!";
		break;
    }
    return 0;
}
What does your compiler tell you are the problems?
As jlb said, the compiler should be telling you what and where your problems are. Compiler error messages can sometimes be somewhat cryptic, but will tell you the line number where the compiler discovered a problem.

Line 3: The second argument to your function prototype makes no sense. n is undefined. Even if n were defined at this point, [n] makes no sense as an argument.

You have no implementation for insertion(), which will cause linker errors.

Your calls to insertion() do not match your function prototype.

Line 4: The ; terminates statement making this a function prototype.

Line 4,114: You have two main() functions.

Line 10,15,22,23,27: Array a is never defined.

Line 29,32,33,38: n is not defined.

Line 43,44: pos is not defined.

Line 139,143: This is a function prototype, not a function call. Get rid of the void.

There are more errors, but this should get you started. When you're just getting started, it is easiest to find and fix the first compiler error, recompile and move on to the next error.


Topic archived. No new replies allowed.