Questions tagged [fizzbuzz]

a game, algorithm and a common programming task of replacing any number divisible by three with the word "fizz", and any number divisible by five with the word "buzz"

Fizzbuzz is a game used to teach children division. Implementing an algorithm for that game is sometimes used as an interview task.

https://en.wikipedia.org/wiki/Fizz_buzz

290 questions
-2
votes
1 answer

C# variable scope for instantiating a class

I am going through the FizzBuzz kata and trying to do it in as much of an object orientated way as possible, just started learning C#. In that pursuit, I am trying to use a class called, MessageStore to store various strings and integers to be…
3therk1ll
  • 2,056
  • 4
  • 35
  • 64
-2
votes
1 answer

Why is my FizzBuzz method not working

I was instructed to make a FizzBuzz class that has a fizzBuzz method that takes in two int values as parameters. It is not working properly and I am wondering why? public class FizzBuzz { public static void main(String[] args) { int start =…
ObiJuanKanobe
  • 45
  • 1
  • 6
-2
votes
1 answer

Code for "fizzbuzz" doesn't work. Only "fizzbuzz" returned multiple times

Can someone please explain why the following code does not work properly? It only returns "fizzbuzz" 100 times as the answer. Thank you. def fizzbuzz(number) idx = 0 while idx <= number num = number[idx] if num % 3 == 0 && num % 5 == 0 …
Asfand
  • 1
  • 4
-2
votes
2 answers

Using `map` to solve 'FizzBuzz'

I tired to use map to solve fizzbuzz. def fizzbuzz(n) array =(1..n).to_a array.map{|x| if x % 3 == 0 && x % 5 == 0 x = 'FizzBuzz' elsif x % 3 == 0 x = 'Fizz' elsif x % 5 == 0 x = 'Buzz' …
Han Jiang
  • 41
  • 3
  • 10
-2
votes
3 answers

FizzBuzz, java code

I am trying to create a piece of code for the game 'fizzbuzz', if n|3 => n=Fizz, if n|5 => n= Buzz and if n|3 and n|5 then n=Fizzbuzz. For some reason my code only displays 46 lines of code, can someone help me out? Thanks. Here is my code: import…
GentleCynic
  • 73
  • 1
  • 9
-2
votes
4 answers

I am encountering an error with my code for fizzbuzz

#include using namespace std; int f[33] = {3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 57, 60, 63, 66, 69, 72, 75, 78, 81, 84, 87, 90, 93, 96, 99}; int b[20] = {5, 10, 15, 20, 25, 30, 35, 40, 45,…
daesad
  • 55
  • 6
-2
votes
1 answer

Cannot assign to 'writeline' because it is a 'method group'

The below code is giving me error "Cannot assign to 'writeline' because it is a 'method group;" at every Console.Writeline statement. I am trying to find out why but I could not find anything to point me in right direction. Any help appreciated.…
HereToLearn_
  • 1,150
  • 4
  • 26
  • 47
-2
votes
2 answers

FizzBuzz with commas instead of newlines

def fizz_buzz(i): if i % 15 == 0: return ("FizzBuzz") elif i % 5 == 0: return ("Buzz") elif i % 3 == 0: return ("Fizz") else: return (i) for i in range(1, 21): print(fizz_buzz(i)) Where and how would do a new line command here…
Gilgamesh
  • 29
  • 5
-2
votes
1 answer

Please help me with this error in simple fizzbuzz program

Syntax error near unexpected token 'if' for x in 1..100 if x % 3 == 0 puts "Fizz" elsif (x % 5) == 0 puts "Buzz" else puts x end end
goofiw
  • 19
  • 3
-2
votes
3 answers

FizzBuzz in assembly - segmentation fault

I am trying to write FizzBuzz in Assembly and I am seeing segmentation fault all the time. So far I have determined that it is not my printing routines (because I have removed their contents and the problem persists) and the error hides somewhere in…
kacpr
  • 440
  • 1
  • 8
  • 28
-2
votes
1 answer

Fizzbuzz in C++. printing each string prior to integer printing

Tried writing fizzbuzz out in C++, but prior to the console printing the list of integers it prints each string "Fizzbuzz, "fizz", "buzz" Sample output: Fizzbuzz Fizz Buzz 1 2 Fizz 4 Code: #include using namespace…
ayeteo
  • 244
  • 3
  • 5
  • 14
-2
votes
1 answer

Fizz Buzz script using while loop stuck in infinite loop - php

I'm trying to write a Fizz Buzz script using a while loop to cycle through the numbers 1-100 and echo each one to the screen. I'm using the modulus operator to find if a number is a multiple of: 3 in which case it echos Fizz, 5 in which case it…
sam
  • 9,486
  • 36
  • 109
  • 160
-3
votes
9 answers

What is the best solution to this? (Any Language)

Here is a question. Can someone figure out the answer? Maximum two "if" tests are allowed! Given numbers from 1 to 100 If this number is divisble by 21 print "foobar" If this number is divisble by 7 print "bar" If this number is divisble by 3 print…
Kevin
  • 5,972
  • 17
  • 63
  • 87
-3
votes
1 answer

How can I create a function that will allow a user to input a piece of code

I am creating a fizzbuzz game and i would like to create a function that allows the user to input a new rule into the code when it reaches 21. If anyone has any solutions i would be very grateful. Btw I am a year 10 student so a simple solution…
-3
votes
3 answers

How to Unit Test this method with C#

I have the following method, which I want to perform a unit test on. Change can be made for the method signature: public void PrintNumber() { Enumerable.Range(1, 100).ToList().ForEach(x => { if (x % 3 == 0 && x % 5 == 0) …
Pingpong
  • 7,681
  • 21
  • 83
  • 209