Write a statement that toggles the value of the bool variable onOffSwitch . That is, if onOffSwitch is false , its value is changed to true ; if onOffSwitch is true , its value is changed to false .

2
Write a statement  that toggles the value  of the bool variable  onOffSwitch . That is, if onOffSwitch is false , its value  is changed to true ; if onOffSwitch is true , its value  is changed to false .

LANGUAGE: C++

CHALLENGE:

Write a statement  that toggles the value  of the bool variable  onOffSwitch . That is, if onOffSwitch is false , its value  is changed to true ; if onOffSwitch is true , its value  is changed to false.

SOLUTION:


if(onOffSwitch){
  onOffSwitch = false;
}else{
  onOffSwitch = true;
}

2 comments

Add comment