why is the code not executing as expected?

so I want to write a program that if you didn't write the number 5 ten times you'll get praised other you'll get scolded.
I used int x as a counter for how many times he didn't write the number 5.
Note: after the if in the loop executed it goes out of the loop why!
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
#include <iostream>
#include <cstdio>

int main()
{
	int x = 1;
	int a ;
	int b = 0;
	std::cout << "Don't write the number 5: ";
	std::cin >> a;

	if (a != 5) {
		for (int i = 0; i != 5; i = a) {
			x++;
			std::cout << "Write another number other then 5: ";
			std::cin >> a;
			if (x = 10) {
				a = 5;
				b = 5;
			}
		}
		}
		if (b = 5) {
		std::cout << "You weren't supposed to write the number 5!";
			for (int i = 0; i = 4;) {
				std::cin >> a;
			};
		}
		std::cout << "you are so patient :)";
		for (int i = 0; i = 4;) {
			std::cin >> a;
		};
	
}
if (b = 5) { should probably read if (b == 5) {
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>

int main()
{
    const int N = 10 ;
    const int AVOID_THIS = 5 ;

    std::cout << "enter " << N << " integers. do not enter the number " << AVOID_THIS << '\n' ;

    bool bad_input = false ;

    for( int i = 0 ; i < N ; ++i )
    {
        std::cout << "number? " ;
        int number ;
        std::cin >> number ;
        if( number == AVOID_THIS ) bad_input = true ;
    }

    if(bad_input) std::cout << "You weren't supposed to write the number " << AVOID_THIS << "!\n" ;
    else std::cout << "you are so patient :)\n" ;
}
Thank you guys :)
Topic archived. No new replies allowed.