dimanche 28 novembre 2021

Why is my if statement working even though it's not supposed to be right? [closed]

I started doing a code some time ago but I got into this problem that I see that It's supposed to not be correct, but for some reason is working.

#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
    ...
    string map1;
    string map2;
    ...
    bool free = true;
    cin >> map1;  
    cin >> map2;   
    int c = 0;
    for (size_t i = 0; i < map1.size(); i++) {
        cout << map1[c] << map2[c];             //starting characters of each string
        if (map1[c] != 0 && map1[c] != 1) {
            cout << free;
            free = false;
            cout << i;
            i = map1.size();
        }
        else if (0 != map2[c] && 1 != map2[0]) {
            cout << free;
            free = false;
            cout << i;
            i = map1.size();
        }
        c++;
    }
    ...
    return 0;
}

Aucun commentaire:

Enregistrer un commentaire