Drop links or images here to add them to the editor.

A counting game for children.

★★☆

Fizz buzz is a counting game for children to teach them about division. Players take turns to count incrementally, replacing any number divisible by three with the word "fizz", and any number divisible by five with the word "buzz".

Fizz buzz

Make

Write a program to show the output of the game Fizz Buzz up to a number entered by the user.

Success Criteria

Remember to add a comment before a subprogram, selection or iteration statement to explain its purpose.

Complete the subprogram called fizz_buzz that:

  1. Takes one parameter, x that is the number to count up to.
  2. For multiples of 3 and 5 it outputs, "Fizz Buzz".
  3. For multiples of 3 only it outputs, "Fizz".
  4. For multiples of 5 only it outputs, "Buzz".
  5. For any other number it outputs the number.
  6. Note that the count starts at one, increments by one and ends at the last number.

Complete the main program so that:

  1. The user can input the number to count up to.
  2. It calls the fizz_buzz subprogram.

Typical inputs and outputs from the program would be:

What number should the count be up to?
15
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
Fizz Buzz
🆘 If you're really stuck, use this Parsons code sorting exercise
Complete program
// Fizz buzz program

using System;

class Submission
{
---
    // -------------------------
    // Subprograms
    // -------------------------
    // Subroutine to output Fizz for multiples of 3 and Buzz for multiples of 5
    static void fizz_buzz(int x)
    {
---
        // Loop from 1 to x
        for (int counter = 1; counter <= x; counter++)
        {
---
            // Multiple of 3 and 5
            if (counter % 3 == 0 && counter % 5 == 0)
            {
---
                Console.WriteLine("Fizz Buzz");
---
            }
---
            // Multiple of 3 only
            else if (counter % 3 == 0)
            {
---
                Console.WriteLine("Fizz");
---
            }
---
            // Multiple of 5 only
            else if (counter % 5 == 0)
            {
---
                Console.WriteLine("Buzz");
---
            }
---
            // Not multiple of 3 or 5
            else 
            {
---
                Console.WriteLine(counter);
---
            }
---
        }
---
    }


---
    // -------------------------
    // Main program
    // -------------------------
    public static void Main(string[] args)
    {
---
        Console.WriteLine("What number should the count be up to?");
        int maximum = Convert.ToInt32(Console.ReadLine());
        fizz_buzz(maximum);
---
    }
}