

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 4
click for more info
Not enough gems
Cost: 6 gems
1: Welcome to Memory Management
incomplete
2: C Program Structure
incomplete
3: Interpreted Quiz
incomplete
4: C Is Compiled
incomplete
5: Comments
incomplete
6: Basic Types
incomplete
7: Strings
incomplete
8: Printing Variables
incomplete
9: Compilation: Types
incomplete
10: Variables
incomplete
11: Constants
incomplete
12: Functions
incomplete
13: Void
incomplete
14: Unit Tests
incomplete
15: Math Operators
incomplete
16: If Statements
incomplete
17: Logical Operators
incomplete
18: Ternary
incomplete
19: Type Sizes
incomplete
20: Sizeof
incomplete
21: For Loop
incomplete
22: While Loop
incomplete
23: Do While Loop
incomplete
24: Pragma Once and Header Guards
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
if statements are the most basic form of control flow in C: very similar to other languages. Basic syntax:
if (x > 3) {
printf("x is greater than 3\n");
}
if/else/else if are also available:
if (x > 3) {
printf("x is greater than 3\n");
} else if (x == 3) {
printf("x is 3\n");
} else {
printf("x is less than 3\n");
}
You can write an if statement without braces if you only have one statement in the body:
if (x > 3) printf("x is greater than 3\n");
Buuuuut this shorthand is easy to mess up and in my opinion isn't worth saving a couple lines. There are enough ways to shoot yourself in the foot in C already.
Take a look at exercise.h. Write the implementation for the function prototype found there back in exercise.c. It should calculate whether the given temperature is too cold or too hot (it's already in Fahrenheit of course, the most reasonable scale for regular living).
Do not add the \n to the end of the strings. That's done at print-time.