Congratulations on completing the lesson on conditionals! 🙌
Let’s review some of the major concepts from the lesson:
ifstatement checks a condition and will execute a task if that condition evaluates to true.
elsestatements make binary decisions and execute different code blocks based on a provided condition.
- We can add more conditions using
- Relational operators, including
!=can compare two values.
- Logical operators, including
!can allow multiple conditions in one conditional statement.
switchstatement can be used to simplify the process of writing multiple
else ifstatements. The
breakkeyword stops the remaining cases from being checked and executed in a
- A ternary operator can be used to simplify the process of an
Optional: Little Mac is an interplanetary space boxer, who is trying to win championship belts for various weight categories on other planets within the solar system.
Write a space.c program that helps him keep track of his target weight by: It should ask him what his earth weight is. Ask him to enter a number for the planet he wants to fight on. It should then compute his weight on the destination planet.
Compile and execute:
gcc space.c ./a.out
Here is the table of conversion: