Programming Forums
User Name Password Register
 

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

Reply
 
Thread Tools Display Modes
Old Dec 4th, 2005, 3:18 PM   #1
Haz
Programmer
 
Haz's Avatar
 
Join Date: Feb 2005
Location: England
Posts: 37
Rep Power: 0 Haz is on a distinguished road
Send a message via ICQ to Haz Send a message via AIM to Haz Send a message via MSN to Haz Send a message via Yahoo to Haz
Controlling Number Of Dots With Modulo

Hullo,

I'm trying to reduce the number of dots being printed to the screen, here's the code I attempted at trying:

         else {
                dots++;
                dots %= 10;
                if ( dots = 0 ) {              
                cout << "...\n"; // If "hsr" isn't an integer, output "..." to the screen
                }
              }

It increments dots, peforms a modulo operator, and if it's dividable (sp?) by 10, it prints the dots, but I tried this and it doesn't seem to work (it doesn't print ANYTHING now). I was wondering what I was doing wrong and how to put it right.

Thanks,

Haz.
__________________
MY BLOG :eek:

AND WEBSITE :eek:
Haz is offline   Reply With Quote
Old Dec 4th, 2005, 3:20 PM   #2
UnKnown X
Hobbyist Programmer
 
UnKnown X's Avatar
 
Join Date: Dec 2005
Location: Sandvika, Norway
Posts: 114
Rep Power: 0 UnKnown X is an unknown quantity at this point
Send a message via MSN to UnKnown X
A common error.

if ( dots = 0 )  // WRONG
if (dots == 0 )  // RIGHT

I think you can spot the error.
UnKnown X is offline   Reply With Quote
Old Dec 4th, 2005, 3:22 PM   #3
Haz
Programmer
 
Haz's Avatar
 
Join Date: Feb 2005
Location: England
Posts: 37
Rep Power: 0 Haz is on a distinguished road
Send a message via ICQ to Haz Send a message via AIM to Haz Send a message via MSN to Haz Send a message via Yahoo to Haz
Ah, damn, I knew it was something simple, thanks
__________________
MY BLOG :eek:

AND WEBSITE :eek:
Haz is offline   Reply With Quote
Old Dec 5th, 2005, 8:30 AM   #4
lectricpharaoh
SEXY SHOELESS GOD OF WAR!
 
lectricpharaoh's Avatar
 
Join Date: Jun 2005
Location: Wet west coast of Canada
Posts: 1,183
Rep Power: 5 lectricpharaoh will become famous soon enough
Quote:
Originally Posted by Haz
Ah, damn, I knew it was something simple, thanks
I've said it before, and I'll say it again: if you regularly have this kind of error, you should get in the habit of sticking the constant on the left-hand side of a comparison. Then, if you type something like
if(0 = dots)
you will get a compiler error (constants aren't lvalues). I don't use this trick very often, but I also am comfortable with == instead of =. It's a great trick for people migrating from a language like VB, though, where they have no distinction between the two.
__________________
And once again, Probability proves itself willing to sneak into a back alley and service Drama as would a copper-piece harlot.
- Vaarsuvius, Order of the Stick
lectricpharaoh 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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 9:21 AM.

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