Need an explanation

Why does the variable starhome change to true everytime we loop even if there
isn't any code to make it change to true ?

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

void outside();
void home();


int main(){
    bool starthome = false;


    while (true){

        if ((starthome =! starthome)){ // assignment intentional
            outside();

        }else{
            home();

        }
        std::cout << '\n';
        std::cin.get();
    }
}

void outside(){

    std::cout << "You're outside now";
}

void home(){

    std::cout << "You're home now";
}
It gets assigned to the opposite value at line 13.

if ((starthome = !starthome)){ // assignment intentional
Ah lol, my bad

Thanks
Topic archived. No new replies allowed.