What, in your opinion, is the easiest way of removing the repetitiveness of this FizzBuzz program?
I hate having to repeat if statements, it annoys me.
Also, general fizzbuzz thread.
Also, if you think my code looks bad, then suck a dick because I did it in Vim because I'm too lazy to install a real text editor. So I don't have syntax highlighting, and compilation errors in g++ are cryptic at best.Code:#include <iostream> using namespace std; int main() { int count = 1; do { if(!(count%3)) { if(!(count%5)) { cout << "FizzBuzz" << endl; } } if(!(count%3)) { cout << "Fizz" << endl; } if (!(count%5)) { cout << "Buzz" << endl; } else { cout << count << endl; } count++; } while(count<100); }
Anyway, yep. Anyone know any other programming interview challenges that are fun?
Results 1 to 4 of 4
Thread: Repetitiveness
- 15 Aug. 2013 03:10am #1
- Join Date
- Apr. 2010
- Location
- When freedom is outlawed only outlaws will be free
- Posts
- 5,113
- Reputation
- 195
- LCash
- 0.25
Repetitiveness
- 15 Aug. 2013 03:45am #2
You don't have to end the line with every cout.
Code:if (!(count % 3)) cout << "Fizz"; if (!(count % 5)) cout << "Buzz"; if (count % 3 || count % 5) cout << count; cout << endl;
- 15 Aug. 2013 02:35pm #3
- Join Date
- Apr. 2010
- Location
- When freedom is outlawed only outlaws will be free
- Posts
- 5,113
- Reputation
- 195
- LCash
- 1.24
- 16 Aug. 2013 04:20am #4
Using a do while loop is a tad redundant, particularly since you're just incrementing . You're better off using a for loop.