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

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…

Contents