HackerRank Python Compilation Error in Void Function: expected ‘,’ or ‘;’ before ‘while’ OR unused variable

  compiler-errors, python, void, while-loop

The goal of the exercise is to print a list of numbers from 1 to n, but if the number is divisible by 3, 5, or both 3 & 5, you print out "Fizz", "Buzz", or "Fizzbuzz" respectively. I’ve never used a void function before, and keep getting an errors to these effects:

  1. expected ‘,’ or ‘;’ before ‘while’
    while count <= n:
  2. warning: unused variable ‘count’ [-Wunused-variable]
    int count = 1

Please advise:

void fizzBuzz(int n) {
    int count = 1
    while count <= n:
        if count%3==0:
            if count%5 == 0:
                print("Fizzbuzz")
            else:
                print("Fizz")
        if count%5==0:
            print("Buzz")
        else:
            print(n)
        count+=1
}

Source: Python Questions

LEAVE A COMMENT