Solving the Fizz Buzz problem
Fizz Buzz is a common programming problem that is a great way to challenge yourself at flow control. Before you begin, there are two C# concepts you should know about that will help you solve the problem. The first is else..if
, which is another addition to the if..else
statement, while the second is the remainder operator. Let’s briefly return to the if..else
statement in MyBudget
, where we have added a Boolean called bookOnSale
.
Using else..if
else..if
statements allow for more branching, where you can add conditions that can be tested if the condition in the if
statement is false. In the following example, the if..else
statement in MyBudget
has been modified to include an else..if
statement:
decimal bookPrice = 25; bool bookOnSale = true; bool canAffordBook = VerifyAffordable(bookPrice); if (canAffordBook) { Â Â Â Â Console.WriteLine("You can afford to buy the book!"); Â Â Â Â CalculateNewBalance...