From the course: C Programming Basics: Flow Control, Variables, and Pointers
Unlock the full course today
Join today to access over 23,400 courses taught by industry experts.
Solution: Make a decision - C Tutorial
From the course: C Programming Basics: Flow Control, Variables, and Pointers
Solution: Make a decision
(upbeat music) - I hope you explored various opportunities for solving this challenge like many programming puzzles, more than one solution is possible. And no one solution is the perfect one. If you opted to use an if else structure, then this could be a potential solution. After input is obtained at lines seven and eight, the first if statement checks for one and displays the appropriate text. Else ifs checks at line 14 for the value two, and then at line 18 for the value three. And then finally at line 22, the final else detects whatever's invalid and prints the message, invalid input. Potential mistakes with this type of solution could be, forgetting to equal signs. Remember to think is equal to not equals when you concoct an if statements evaluation. Also, following an if else if or else statement with a semi-colon results in a compiler warning. If not, the code won't run properly. All those braces in the…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
Making a decision with if5m 21s
-
(Locked)
Making multiple decisions4m 3s
-
(Locked)
Challenge: Make a decision32s
-
(Locked)
Solution: Make a decision1m 36s
-
(Locked)
Looping with while5m 28s
-
(Locked)
Repeating chunks of code with for3m 25s
-
(Locked)
Challenge: Output a series of numbers30s
-
(Locked)
Solution: Output a series of numbers1m 45s
-
(Locked)
Nested loops2m 50s
-
Understanding functions3m 10s
-
(Locked)
Adding a function4m 12s
-
(Locked)
Passing values to a function2m 28s
-
(Locked)
Challenge: Evaluate a number31s
-
(Locked)
Solution: Evaluate a number1m 16s
-
(Locked)
Returning a value from a function3m 41s
-
-
-
-