Boolean switch/selection structure?

Literaly the second day I've been working on this.
I was given instructions to create a boolean switch program that would accept boolean values as input for a, b, and, c in that order but was told it could only be done using three conditionals and 3 flips. Once it runs, it would execute pseudocode:

- if a is true, flip the value of b
-THEN if b is true, flip the value of c
-THEN if c is true, flip the value of a.

Finally, outputting a, b, and c.

So the input/output would look like this:

>101
<110

or

>100
<011

so far, i have the following

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
using namespace std;

int main() {
     cout << "Please enter 1 or 0 for a, b, and c in that order." << endl;

     bool a, b, c;

     cin >> a >> b >> c;

     if (a) {
          b = !b;
     }
     if (b) {
          c = !c;
     }
     if (c) {
          a = !a;
     }
     cout << a << b << c << endl;


but the issue im having with is the input. It works perfectly if I input the three values separately instead of on the same line
Last edited on
Really I;m having issues with having it check the new set of numbers that should be outputted after each "if " statement.
Last edited on
100 doesn't give you 001.
if a is 1 then b is automatically 1...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
using namespace std;

int main() {

        cout << "Please enter 1 or 0 for a, b, and c in that order." << endl;

        bool a, b, c;
        cin >> a >> b >> c;

        if(a == 1){
                b = !b;
                if (b == 1){
                        c = !c;
                        if (c == 1) {
                                a = !a;
                        }
                }
        }
        cout << a << b << c << endl;

        return 0;
}


Last edited on
Ok, ya, sorry, Typo on my end.

However, I'm still having the same issue. If i try to input all three on the same line, it just outputs 000. But if I input one at a time, it works. Is there a way around this?
im guessing there's a class to convert a string into chars into bools, never heard of it though. I'm a beginner also.
Thanks for the reply but the issue is the way its inputted. If i input them comma or space separted on one line, it works. but i can't have them one right after the other, which is what i would like
Just input the numbers with spaces between them. I.e., 1 0 1 instead of 101
Topic archived. No new replies allowed.