Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Feb 28th, 2007, 2:42 PM   #21
milot
Programmer
 
milot's Avatar
 
Join Date: Nov 2006
Location: Kosovė/Prishtinė
Posts: 47
Rep Power: 0 milot is on a distinguished road
Quote:
Originally Posted by DaWei View Post
Milot, for C++, I'd take the hint from Jim and reduce the number of calculations. This may be easier to read:
	for (int i = 1; i <= 100; ++i)
	{
		int t = i % 3;
		int f = i % 5;
		if (t && f) cout << i;
		else
		{
			if (!t) cout << "Fizz";
			if (!f) cout << "Buzz";
		}
	   cout << endl;
	}
Thank you DaWei, it's true that your snippet reduced calculations and it's very easy to read. . But I just wrote that what's came in my mind fast, I didn't think about reducing calculations. But the logic works though.
milot is offline   Reply With Quote
Old Feb 28th, 2007, 7:21 PM   #22
Indigno
Professional Programmer
 
Indigno's Avatar
 
Join Date: Dec 2005
Location: Anywhere non-productive
Posts: 267
Rep Power: 0 Indigno is an unknown quantity at this point
Send a message via AIM to Indigno Send a message via MSN to Indigno Send a message via Yahoo to Indigno
QBASIC:
FOR I=1 TO 100
 IF (I%3)=0 AND (I%5)=0
  PRINT "FizzBuzz" 
 ELSEIF (I%3)=0
  PRINT "Fizz"
 ELSEIF (I%5)=0
  "Buzz"
NEXT I

If I got that wrong, give me a break. I haven't used QB in over a year.

This is good for me, because I got just about everything except recursion down on that page and I'm not even through my first year of C++.
__________________
Perhaps I should have a sticky topic for all of the times I "return" to this forum instead of a new one every time.
Indigno is offline   Reply With Quote
Old Feb 28th, 2007, 7:23 PM   #23
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
So, when do you print 'I'????
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Feb 28th, 2007, 7:56 PM   #24
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 843
Rep Power: 3 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
If you look at the comments at the bottom of the Coding Horror article, a number of people posted the code they wrote to solve the FizzBuzz problem. It's frightening how many people posted incorrect code; they either forgot to print the number (like Indigno), or printed "buzz" instead of "fizz", or printed the number after printing "fizz" and/or "buzz"... and that's just the few I noticed.
titaniumdecoy is offline   Reply With Quote
Old Jun 17th, 2007, 8:48 PM   #25
scm007
Newbie
 
Join Date: Jan 2006
Posts: 27
Rep Power: 0 scm007 is on a distinguished road
read too quickly
scm007 is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Language display in program Prm753 C++ 3 May 30th, 2006 5:45 PM
Creating a program to test a program sixstringartist C 8 Jan 21st, 2006 1:15 PM
auto run hidden program. kuroko C++ 9 Aug 6th, 2005 10:05 AM
Program gets aborted on large input shinni C++ 3 Mar 12th, 2005 8:26 AM
airport Log program using 3D linked List : problem reading from file gemini_shooter C++ 0 Mar 2nd, 2005 4:12 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:34 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC