vendredi 16 décembre 2016

How can I remedy this if statement?

I am trying to create a simple, 'fizzbuzz' program where every time a multiple of 3 is printed, 'fizz' is printed beside it and every time a multiple of 5 is printed, 'buzz' is printed beside it. However, what happens instead in this program is that the first if statement is true every time and the output is every number having, 'Buzz!' beside it. Why is this happening? What do I need to realize in order to program this correctly?

for(int index = 1; index <= 100; ++index) {
    cout << index << endl;
    if (index == 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100)
        cout << " Buzz!" << endl;
    else if(index == 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)
        cout << " Fizz!" << endl;
}

Aucun commentaire:

Enregistrer un commentaire