Error on pass by reference.

I'm having a problem compiling a small piece of code on Borland Turbo C++ 3. I get an error saying i need my parenthesis directly before the variable "vec", right after the ampersand. I've tried messing with it for a while and i still can't get it to run. Thanks for the help.


Error: ) Expected


1
2
3
4
5
6
7
8
9
10
void checkvec(int x, int y, int &vec, int size)
{
...
};
int main(void)
{
...
changevec(x, y, vec, size); 
...
};
Borland... Turbo C++... three!?

Please, please, please upgrade to something more recent, like the newest MinGW. After all, Turbo C++ 3 was created before the language was even standardized. Thanks. :\
http://sourceforge.net/projects/mingw/files/

-Albatross
Last edited on
The names of those functions don't match....

++Albatross
Also, function don't end with '};'. In this case, just '}' will do. Also, what the above said.
classes and structs are }; for objects
Galik (2164) Jan 19, 2012 at 1:37am
The names of those functions don't match....

++Albatross

Thanks, got that fixed.


Borland... Turbo C++... three!?
...
-Albatross

I know what you mean, I am required to use the borland compiler for a college class i'm taking. (I use mingw at home)

The only reason i don't compile with mingw/gcc is because i'm required to use graphics.h from the borland compiler.

Here is the entire code.
The only errors i get are the places i use call by reference.

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
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <dos.h>
#include <time.h>

void checkvec(int x, int y, int &vec, int size)  //Checks to see if object has touched a side of the screen
{
	 if(x<=0+size && y<=0+size)         vec = 6;  //corner of the screens
    else if(x>=xmax-size && y>=ymax-size)   vec = 14;
    else if(x<=0+size && y>=ymax-size)      vec = 2;
    else if(x>=xmax-size && y<=0+size)      vec = 10;

    else if(x<=0+size && vec>=12)           vec = (random(3)+1);  //left side of screen
    else if(x<=0+size && vec<12)            vec = (random(3)+5);

    else if(x>=xmax-size && vec>=4)         vec = (random(3)+9);  //right side of screen
    else if(x>=xmax-size && vec<4)          vec = (random(3)+13);

    else if(y<=0+size && vec>=12)           vec = (random(3)+9);  //top of screen
    else if(y<=0+size && vec<=4)            vec = (random(3)+5);

    else if(y>=ymax-size && vec>=8)         vec = (random(3)+13);  //bottom of screen
    else if(y>=ymax-size && vec<8)          vec = (random(3)+1);
};

void cyclexy(int &x, int &y, int vec)   //Changes x, y based on current direction of input
{
    if(vec==0){y--;};			//0
    if(vec==1){x++;y--;y--;};   //30
    if(vec==2){x++;y--;};       //45
    if(vec==3){x++;x++;y--;};   //60
    if(vec==4){x++;};			//90
    if(vec==5){x++;x++;y++;};	//120
    if(vec==6){x++;y++;};		//135
    if(vec==7){x++;y++;y++;};	//150
    if(vec==8){y++;};			//180
    if(vec==9){x--;y++;y++;};	//210
    if(vec==10){x--;y++;};		//225
    if(vec==11){x--;x--;y++;};	//240
    if(vec==12){x--;};			//270
    if(vec==13){x--;x--;y--;};	//300
    if(vec==14){x--;y--;};		//315
    if(vec==15){x--;y--;y--;};	//330
};

void printlogo(int &x, int &y, int &vec)           //Prints out a series of circles in a circle
{
    if(vec == 15);
    else
    {
	circle (x, y, 3);
	cyclexy(x, y, rvec);
	cyclexy(x, y, rvec);
	printlogo(x, y, ++vec);
    };
};

int main(void)
{
    int gdriver = DETECT, gmode, errorcode;
    int xmax, ymax, x, y, vec, rx, ry, rvec, size;
    void far * ptr;

    initgraph(&gdriver, &gmode, "");
    errorcode = graphresult();
    if (errorcode != grOk)
    {
	printf("Graphics error: %s\n", grapherrormsg(errorcode));
	printf("Press any key to halt:");
	getch();
	exit(1);
    };
    setcolor(getmaxcolor());    //Initializing
    xmax = getmaxx();
    ymax = getmaxy();
    x = xmax/2;
    y = ymax/2;
    vec = 0;
    ptr = malloc(imagesize(x, y, x+size, y+size);
    printlogo(x, y, vec);  //Prints out the logo
    vec = random(16);
    clearscrn();

    while(1)                    //Main loop,
    {
	checkvec(x, y, vec, size); //Checks to see if object is out of bounds, changes direction if it is
	cyclexy(x, y, vec);         //Moves the object along the path
	getimage(x, y, x+size, y+size, ptr);
	putimage(x, y, x+size, y+size, ptr, XOR-PUT);
	delay(3);
	putimage(x, y, x+size, y+size, ptr, XOR-PUT);
    };

    /* clean up */
    getch();
    closegraph();
    return 0;
};
Last edited on
closed account (o1vk4iN6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
    if(vec==0){y--;};			//0
    if(vec==1){x++;y--;y--;};   //30
    if(vec==2){x++;y--;};       //45
    if(vec==3){x++;x++;y--;};   //60
    if(vec==4){x++;};			//90
    if(vec==5){x++;x++;y++;};	//120
    if(vec==6){x++;y++;};		//135
    if(vec==7){x++;y++;y++;};	//150
    if(vec==8){y++;};			//180
    if(vec==9){x--;y++;y++;};	//210
    if(vec==10){x--;y++;};		//225
    if(vec==11){x--;x--;y++;};	//240
    if(vec==12){x--;};			//270
    if(vec==13){x--;x--;y--;};	//300
    if(vec==14){x--;y--;};		//315
    if(vec==15){x--;y--;y--;};	//330 


You could probably make that a switch statement along with an 'enum' or at least make it "else if" so if you do end up finding the 'vec' your looking for you won't check the rest.
You could probably make that a switch statement along with an 'enum' or at least make it "else if" so if you do end up finding the 'vec' your looking for you won't check the rest.

Fixed thanks.
Topic archived. No new replies allowed.