Compile error..

Jun 6, 2013 at 12:47am
I just wrote this code to implement a basic function but I am getting weird compile errors. I am using Ubuntu and compiling on bash via g++.

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

void array_printer(int arr[], int size,int arr1[]) 
{
int i,j,k;

if 	(arr[size] == 0)
	{ cout <<"Impossible"<< endl;}

else	
	for (i=0, i<size, i++)
	{
	cout << arr1[i]" x "arr[i]; 
	}
    	
}


int main() 
{

int n,i,k,j,l;
int arr[n];
int arr1[n]; 

cin >> n; 

if (!cin.fail())
	{
		for (i=0, i < n+1, i++) 
		{
			cin >> j;
			arr[n];
			arr[i] = j;
		}

	l = arr[n];
		
		for (k=0, k < n+1, k++)
		{
 			arr1[k] = l/arr[k]; 
 			l = l % arr[k]; 
		}	 	
	}
array_printer(arr, n, arr1);

return 0;
 
}		


The compile error is the following:
a2q2.cc: In function ‘void array_printer(int*, int, int*)’:
a2q2.cc:14: error: expected ‘;’ before ‘)’ token
a2q2.cc:19: error: expected primary-expression before ‘}’ token
a2q2.cc:19: error: expected ‘;’ before ‘}’ token
a2q2.cc:19: error: expected primary-expression before ‘}’ token
a2q2.cc:19: error: expected ‘)’ before ‘}’ token
a2q2.cc:19: error: expected primary-expression before ‘}’ token
a2q2.cc:19: error: expected ‘;’ before ‘}’ token
a2q2.cc: In function ‘int main()’:
a2q2.cc:33: error: expected ‘;’ before ‘)’ token
a2q2.cc:42: error: expected primary-expression before ‘for’
a2q2.cc:42: error: expected ‘)’ before ‘for’
a2q2.cc:42: error: expected ‘;’ before ‘)’ token
a2q2.cc:47: error: expected primary-expression before ‘}’ token
a2q2.cc:47: error: expected ‘;’ before ‘}’ token
a2q2.cc:47: error: expected primary-expression before ‘}’ token
a2q2.cc:47: error: expected ‘)’ before ‘}’ token
a2q2.cc:47: error: expected primary-expression before ‘}’ token
a2q2.cc:47: error: expected ‘;’ before ‘}’ token

Can anyone help me out to tell me where my syntax is wrong? thanks a lot
Jun 6, 2013 at 12:53am
Line 14,33,42: The correct separator in a for statement is a ; not a ,
 
for (i=0; i<size; i++)



edit:
Line 16 makes no sense. Did you mean?
 
cout << arr1[i] << " x " << arr[i]; 


Edit #2:
Line 26, 27: n is undefined.
Line 29: You can't input the size of an array. The size of an array must be a const or the array must be dynamically allocated.
Last edited on Jun 6, 2013 at 12:59am
Jun 6, 2013 at 12:58am
that's exactly what I intended and what was missing. thank you very much
Topic archived. No new replies allowed.