i need help

I'm trying to write a code so that I can get used to it and not have so much trouble, but that's not working out so well. I'm just look ing at line 31 (I know there are more problems, but I want to go real slow so that I can try to remember)
it keeps saying "error: lvalue required as left operand of assignment" and all I understand of that is error, so I was hoping I could get some help.


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
#include <iostream>

using namespace std;

int pattern();

int main()
{
 pattern();
    return 0;
}

int patter(){
int ptrn[6][6];
int x;
int y;

x=0;
y=0;

ptrn[x][y] + 1;
if (y=5 || y<5){
y+1;
pattern();
}
else{
y-5;
x+1;
pattern();
}
if (x=5 && y=5)
return 0;
}

thanks for you're help!
Pretty much everywhere that you have variable = something in a statement (such as your if statements), it should be ==. The test for equality is ==, whereas = is the assignment operator.

Also if you want to add things, for example to a variable, you'd do it like: x = x + 2 or x += 2. It would help you a lot if you looked over C++ operators again, since that seems to be your main issue right now. The ideas you have seem good enough, you're just using the wrong operators.
Last edited on
Yep, i've fallen for putting only one = in my code so many times.
What are you trying to do?
WhiteWind, even if you put all the right operators in you still get an error.

Error: Main.obj : error LNK2019: unresolved external symbol "int __cdecl pattern(void)" (?pattern@@YAHXZ) referenced in function _main

I don't know if you want to take out int pattern(); because when I made it like this it worked:
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
#include <iostream>
using namespace std;

int patter(){
int x = 0;
int y = 0;
y + 1;
x + 1;
while (1){
if (y==5 || y<=5){
y = y+1;
}
else{
y = y-5;
x = 
	x+1;
}
if (x==5 && y==5)
return 0;
cout << y << endl;
cout << x << endl;
system ("PAUSE");
system ("CLS");
}
}

int main()
{
	patter();
    return 0;
}


Is this what you wanted it to do?

Topic archived. No new replies allowed.