1. Another popular beginner program is FizzBuzz, The idea is simple, You count upwards from 0 to a number, While doing the following: If the number is divisible by three print out Fizz, If its divisible by 5 print out Buzz, If it is divisible by both print out FizzBuzz, Otherwise print out the number.
  2. To do this problem you'll need to: Get input from the user( What number do you count up to? ), Use a loop from 0 to the number, use conditionals( Is it divisible by 5? ). The only thing you are missing is how to know if something is divisible. To do this you need the modulo function. A modulo tells you the remainder after you divide two numbers. In most programming languages modulo is represented by the "%" symbol, For example, 5%5 = 0, 5%6 = 5, and 5%4 = 1.
  3. So, To tell if a number is divisible by 3 in C++ you would write:
    if(number%3 == 0) {
        cout << "Fizz" << endl;
  4. Using your new knowledge, Try to write FizzBuzz!

results matching ""

    No results matching ""