syntax error : identifier 'cout'

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
#include<iostream>
using namespace std;

void main()

{
	int choice;  
	int num[19];
	int Item,k,x;
	int sum,max,min,LOC;
	int j,n;
	int LA[19],temp;
	
	
	do
	
			system ("cls");
		
		cout<<"\n\n\t\t\t Array menu"; // error C2061: syntax error : identifier 'cout'//
		cout<<"\n\t 1-Input Array Data";
		cout<<"\n\t 2-Display Array Values";
		cout<<"\n\t 3-Insert a value";
		cout<<"\n\t 4-Delete a value";
		cout<<"\n\t 5-Search for a value";
		cout<<"\n\t 6-Sort data Items";
		cout<<"\n\t 7-Sum of values";
		cout<<"\n\t 8-Find maximum value";
		cout<<"\n\t 9-Find minimum value";
		cout<<"\n\t\n\t\t Enter choice:";
		cin>>choice;
	
void Inputdata();
void DisplayValues();
void InsertValues();
void DeleteValues();
void SearchValue();
void SortData();
void Sumofvalues();
void MaximumValue();
void MinimumValue();
		//inputdata//
				for (x=0;x<=1;x++)
				{	cout<<"\nEnter an integer:";cin>>num[x];}
		system ("cls");	
		//displayvalues//
		{system("cls");
				cout<<"The numbers in the array are:\n";
				for (x=0;x<=19;x++)
				{cout<<"num[x]<<\n";}
		}
		//insert values//
		{system ("cls");
				cout<<"\nEnter a value to insert:";cin>>Item;
				cout<<"\nAt What position:";cin>>k;
				j=n;
					while (j>=k)
					{ LA[j]=LA[j-1];
					j=j-1;}
				LA [j]=Item;
					n=n+1;
		}
		
		//deleteing values//
		{system ("cls");
				Item=LA[k-1];
				for(j=k;j<n;j++)
				{LA[j-1]=LA[j];}
				n=n-1;
				cout<<"\nItem deleted was:";Item;
				delete LA[j]; // error C2541: delete : cannot delete objects that are not pointers //
				cout<<LA[n];
		}
		//searching values//
			
		{system ("cls");
				LOC=0;
					for(x=0;;) 					if (LA[x]=Item)
						LOC=x;
					if (LOC)
					{cout<<"\nItem was found";
					}
					else
					{
						cout<<"\nsearch was unsuccessful";}
		}
		//sorting data//
		{system ("cls");
				for(x=0;x<=n;x++)
				{for(j=x+1;j<n;j++);
					{if(LA[x]>LA[j])
						{temp=LA[x];
							LA[x]=LA[j];
								LA[j]=temp;
						}
					}
				}

		}
		//sumof values//
		{system ("cls");		sum=0;
				for(x=0;x<20;x++)
					sum=sum+num[x];
					cout<<"\n sum is:"<<sum;
		}
		//maximum value//
		{system ("cls");
				max=num[0];
				for(x=1;x<19;x++)
					if(max<num[x]) 
						max=num[x];
		}
		//minimum value//
		{system ("cls");		min=num[0];
				for(x=1;x<19;x++)
					if(min>num[x])
						min=num[x];
		}
	
			if(choice==1)
				Inputdata();
		
			else if(choice==2)
				DisplayValues();
		
			if(choice==3)
				InsertValues();
				else if(choice==4)
				DeleteValues();
		
			if(choice==5)
				SearchValue();
		
			else if(choice==6)
				SortData();
		
			if(choice==7)
				Sumofvalues();
	
			else if(choice==8)
				MaximumValue();
	
			if (choice==9)
			MinimumValue();
			
		
	}
Last edited on
when I compile it, it gives me a two error errors
C2061: syntax error : identifier 'cout' and error C2541: delete : cannot delete objects that are not pointers, i don't know what I did wrong, I appreciate any hint, thanks in advance
the error is at line 19 and 70, guys i have no idea with the error in my code, thanks guys
why does it complain about the
cout<<"\n\n\t\t\t Array menu"; it says error C2061: syntax error : identifier 'cout'

and the

delete LA[j]; says "error C2541: delete : cannot delete objects that are not pointers "
LA[j] is not a pointer. LA is a pointer to an array of int. When you use the [] notation, you are accessing a byte of data that is not a pointer. It is just an int.
As far as the cout problem... The do on line 17 may have something to do with that. do is part of this command: do{commands}while(expression);
What should i do? T_T iam not that good in english, i didn't get what should i do with my code
@kevinkjt2000 thanks
Remove the stray do and move all of those function prototypes outside of main. Then make main() return an int.
If English is not your best language, you can try out translate.google.com
sorry guys if i can't get it that fast,

so.. what should my code be? thanks
Well like Zhuge said...

1. remove the stray do
2. move the function prototypes outside of int main
3. never use void main it is evil

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;

//function prototypes go before int main
void Inputdata();
void DisplayValues();
void InsertValues();
void DeleteValues();
void SearchValue();
void SortData();
void Sumofvalues();
void MaximumValue();
void MinimumValue();

int main()//never ever use void main it is evil!!!!!!
//http://cboard.cprogramming.com/cplusplus-programming/90562-void-main-evil-use-int-main.html
//reading that forum and following some of the links there should explain how evil it is

{
	int choice;  
	int num[19];
	int Item,k,x;
	int sum,max,min,LOC;
	int j,n;
	int LA[19],temp;
	
//read how to use the do{}while(); command about halfway down this page:
//http://cplusplus.com/doc/tutorial/control/	
	
	
			system ("cls");
		
		cout<<"\n\n\t\t\t Array menu"; // error C2061: syntax error : identifier 'cout'//
		cout<<"\n\t 1-Input Array Data";
		cout<<"\n\t 2-Display Array Values";
		cout<<"\n\t 3-Insert a value";
		cout<<"\n\t 4-Delete a value";
		cout<<"\n\t 5-Search for a value";
		cout<<"\n\t 6-Sort data Items";
		cout<<"\n\t 7-Sum of values";
		cout<<"\n\t 8-Find maximum value";
		cout<<"\n\t 9-Find minimum value";
		cout<<"\n\t\n\t\t Enter choice:";
		cin>>choice;
//function prototypes do not go here	
		//inputdata//
				for (x=0;x<=1;x++)
				{	cout<<"\nEnter an integer:";cin>>num[x];}
		system ("cls");	
		//displayvalues//
		{system("cls");
				cout<<"The numbers in the array are:\n";
				for (x=0;x<=19;x++)
				{cout<<"num[x]<<\n";}
		}
		//insert values//
		{system ("cls");
				cout<<"\nEnter a value to insert:";cin>>Item;
				cout<<"\nAt What position:";cin>>k;
				j=n;
					while (j>=k)
					{ LA[j]=LA[j-1];
					j=j-1;}
				LA [j]=Item;
					n=n+1;
		}
		
		//deleteing values//
		{system ("cls");
				Item=LA[k-1];
				for(j=k;j<n;j++)
				{LA[j-1]=LA[j];}
				n=n-1;
				cout<<"\nItem deleted was:";Item;
				delete LA[j]; // error C2541: delete : cannot delete objects that are not pointers //
				cout<<LA[n];
		}
		//searching values//
			
		{system ("cls");
				LOC=0;
					for(x=0;;) 					if (LA[x]=Item)
						LOC=x;
					if (LOC)
					{cout<<"\nItem was found";
					}
					else
					{
						cout<<"\nsearch was unsuccessful";}
		}
		//sorting data//
		{system ("cls");
				for(x=0;x<=n;x++)
				{for(j=x+1;j<n;j++);
					{if(LA[x]>LA[j])
						{temp=LA[x];
							LA[x]=LA[j];
								LA[j]=temp;
						}
					}
				}

		}
		//sumof values//
		{system ("cls");		sum=0;
				for(x=0;x<20;x++)
					sum=sum+num[x];
					cout<<"\n sum is:"<<sum;
		}
		//maximum value//
		{system ("cls");
				max=num[0];
				for(x=1;x<19;x++)
					if(max<num[x]) 
						max=num[x];
		}
		//minimum value//
		{system ("cls");		min=num[0];
				for(x=1;x<19;x++)
					if(min>num[x])
						min=num[x];
		}
	
			if(choice==1)
				Inputdata();
		
			else if(choice==2)
				DisplayValues();
		
			if(choice==3)
				InsertValues();
				else if(choice==4)
				DeleteValues();
		
			if(choice==5)
				SearchValue();
		
			else if(choice==6)
				SortData();
		
			if(choice==7)
				Sumofvalues();
	
			else if(choice==8)
				MaximumValue();
	
			if (choice==9)
			MinimumValue();
			
		
	}
still gives me an error at line
75 = error C2541: delete : cannot delete objects that are not pointers

and

151 = warning C4508: 'main' : function should return a value; 'void' return type assumed


T_T thanks guys
Last edited on
replace delete LA[j] with LA[j] = 0, and put a return 0 and the end of your main function
Last edited on
Topic archived. No new replies allowed.