Tag Archives: #else

Mastery 16

mastery 16

 

here is my code for mastery 16 showing the use of “else” as a conditional.

here is my code for masteries 15 and 16

<iostream>

using namespace std;

 

int main(){

  int a, c, d;

  char b;

 

  cout <<“does it move? 1) yes 2) no”;

  cin >> (a);

  if (a == 1) {

    cout << “should it move? 1)yes 2)no”;

    cin>>(c);

    if (c == 1) {

      cout << “then no problem 8)”;

 

    }

    else {

      cout << “then use duct tape”;

     }

 

 

 

    }

    else {

      cout <<“Should it move? 1)yes 2)no”;

      cin >>(d);

      if (d==1) {

        cout << “then use DW40”;

    }

    else {

      cout <<“then no problem 8)”;

    }

  }

  return 0;

}

Mastery16

Using conditionals is really useful when you want to execute an action depending of the result of other action; to do that we use “if” and “else” conditional; but when you want to validate more than one condition you have to use “else if” conditional.

First of all we need to know what is the structure for this conditonals, in this link you will find a pp that explain “else” and “else if” conditionals with detail:

https://drive.google.com/file/d/0B-NM4ghaDXBvX3VSc3NZY3lzaEE/view?usp=sharing

The following picture shows a c++ code using conditionals.

Finally, I found information about that in this link:

http://www.tutorialspoint.com/cplusplus/cpp_if_else_statement.htm