for if loop

I dont understad why this code does not work, it doesnt go through loop, but just prints out 1111 all the time
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include "pch.h"
#include <iostream>
using namespace std;

int main()
{
	int a, x, y;
	cout << "Ievadiet skaitli a ";
	cin >> a;
	for (x = 1; x <= 5; x++) {
		if (x = a) {
			y = 1;
			cout << x << y;

		}
	}
}
Line 11

"=" != "=="
(x = a) should be (x == a)
== is used for comparison whereas = is used for assignment.

Be careful with where you use your = and =='s ;)
Topic archived. No new replies allowed.