Click here to Skip to main content
14,664,462 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.
 
GeneralRe: I just had to reference an article I wrote 14 years ago Pin
Daniel Pfeffer17-May-18 18:41
professionalDaniel Pfeffer17-May-18 18:41 
GeneralSilent updates... Pin
dandy7217-May-18 7:27
Memberdandy7217-May-18 7:27 
GeneralRe: Silent updates... Pin
Richard Deeming17-May-18 7:41
mveRichard Deeming17-May-18 7:41 
GeneralRe: Silent updates... Pin
Ron Anders17-May-18 7:53
MemberRon Anders17-May-18 7:53 
GeneralRe: Silent updates... Pin
the goat in your machine17-May-18 16:52
Memberthe goat in your machine17-May-18 16:52 
GeneralRe: Silent updates... Pin
dandy7218-May-18 3:00
Memberdandy7218-May-18 3:00 
GeneralIt's the fault of that lot in the forums I tell you. Pin
Pete O'Hanlon17-May-18 5:40
subeditorPete O'Hanlon17-May-18 5:40 
GeneralRe: It's the fault of that lot in the forums I tell you. Pin
#realJSOP17-May-18 5:59
mva#realJSOP17-May-18 5:59 
inside the for loop:

if count is evenly divisible by 3, write the count and the word "Fizz"
if count is evenly divisible by 5, write the count and the word "Buzz"
if count is evenly divisible by 3 and by 5, write the count and the word "FizzBuzz"

Possible issue (depending on requirements) - if the count is evenly divisible by 3 and by 5, your output will be (showing only the first occurrence)

15 Fizz
15 Buzz
15 FizzBuzz

Whether or not it's "broken" depends entirely on the requirements, since the code looks like it will compile and run fine (absent your response to my question at the end of this post). I think this is what the requirements would (or should) be:

public static void WowMeWithFizzBuzz(int upperLimit)
{
    // Start at 1 and go up to the specified upper limit. This avoids the '0 is FizzBuzz' problem
    for(int count = 1; count <= upperLimit; count++)
    {
        // To avoid the "Fizz Buzz FizzBuzz" problem at iteration 15 (and similar values that 
        // trigger the "FizzBuzz" response), perform the multi-match first, and put an else in 
        // from of the other two if statements.
        if(count % 5 == 0 && count % 3 == 0)
        {
            Console.WriteLine(string.Format("{0} - FizzBuzz",count));
        }
        else if(count % 3 == 0)
        {
            Console.WriteLine(string.Format("{0} - Fizz",count));
        }
        else if(count % 5 == 0)
        {
            Console.WriteLine(string.Format("{0} - Buzz",count));
        }
    }
}

The code above will generate:
3 - Fizz
5 - Buzz
6 - Fizz
9 - Fizz
10 - Buzz
12 - Fizz
15 - FizzBuzz


The output from your original method would be as follows and would require an max value of 16 to get to 15 (not exactly intuitive):
0 - Fizz
0 - Buzz
0 - FizzBuzz
3 - Fizz
5 - Buzz
6 - Fizz
9 - Fizz
10 - Buzz
12 - Fizz
15 - Fizz
15 - Buzz
15 - FizzBuzz


Is your code example useful? Yes. It forces the programmer to fix someone else's code to meet requirements (an every-day real-world situation). BTW, having them add comments to the code to show that they understand what they're doing would be beneficial as well.

BTW, I've never seen the "${variablename}" notation before. Is that something new in .Net?
".45 ACP - because shooting twice is just silly" - JSOP, 2010
-----
You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
-----
When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013


modified 17-May-18 12:31pm.

GeneralRe: It's the fault of that lot in the forums I tell you. Pin
Pete O'Hanlon17-May-18 6:29
subeditorPete O'Hanlon17-May-18 6:29 
GeneralRe: It's the fault of that lot in the forums I tell you. Pin
#realJSOP17-May-18 6:31
mva#realJSOP17-May-18 6:31 
GeneralRe: It's the fault of that lot in the forums I tell you. Pin
Richard Deeming17-May-18 7:03
mveRichard Deeming17-May-18 7:03 
GeneralRe: It's the fault of that lot in the forums I tell you. Pin
#realJSOP17-May-18 7:41
mva#realJSOP17-May-18 7:41 
GeneralRe: It's the fault of that lot in the forums I tell you. Pin
raddevus17-May-18 10:02
mvaraddevus17-May-18 10:02 
GeneralRe: It's the fault of that lot in the forums I tell you. Pin
dandy7217-May-18 7:33
Memberdandy7217-May-18 7:33 
GeneralRe: It's the fault of that lot in the forums I tell you. Pin
#realJSOP17-May-18 7:42
mva#realJSOP17-May-18 7:42 
GeneralRe: It's the fault of that lot in the forums I tell you. Pin
Dan Neely18-May-18 2:48
MemberDan Neely18-May-18 2:48 
GeneralRe: It's the fault of that lot in the forums I tell you. Pin
Jim_Snyder18-May-18 3:49
professionalJim_Snyder18-May-18 3:49 
GeneralRe: It's the fault of that lot in the forums I tell you. Pin
RandyBuchholz17-May-18 9:00
MemberRandyBuchholz17-May-18 9:00 
GeneralRe: It's the fault of that lot in the forums I tell you. Pin
OriginalGriff17-May-18 5:59
mveOriginalGriff17-May-18 5:59 
GeneralRe: It's the fault of that lot in the forums I tell you. Pin
#realJSOP17-May-18 6:37
mva#realJSOP17-May-18 6:37 
GeneralRe: It's the fault of that lot in the forums I tell you. Pin
dandy7217-May-18 7:35
Memberdandy7217-May-18 7:35 
GeneralRe: It's the fault of that lot in the forums I tell you. Pin
#realJSOP17-May-18 7:44
mva#realJSOP17-May-18 7:44 
GeneralRe: It's the fault of that lot in the forums I tell you. Pin
dandy7217-May-18 7:46
Memberdandy7217-May-18 7:46 
GeneralRe: It's the fault of that lot in the forums I tell you. Pin
GKP199217-May-18 17:58
professionalGKP199217-May-18 17:58 
GeneralDefintely needs to be taught Pin
CHill6017-May-18 6:00
mveCHill6017-May-18 6:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.