Web Development

  Homes arrow Web Development arrow Implementing Modulus
 Webmaster Tools
 
Base64 Encoding 
Browser Settings 
CSS Coder 
CSS Navigation Menu 
Datetime Converter 
DHTML Tooltip 
Dig Utility 
DNS Utility 
Dropdown Menu 
Fetch Content 
Fetch Header 
Floating Layer 
htaccess Generator 
HTML to PHP 
HTML Encoder 
HTML Entities 
IP Convert 
Meta Tags 
Password Encryption
 
Password Strength
 
Pattern Extractor 
Ping Utility 
Pop-Up Window 
Regex Extractor 
Regex Match 
Scrollbar Color 
Source Viewer 
Syntax Highlighting 
URL Encoding 
Web Safe Colors 
Forums Sitemap 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
WEB DEVELOPMENT

Implementing Modulus
By: Developer Shed
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 1 stars1 stars1 stars1 stars1 stars / 1
    2004-05-27

    Table of Contents:

    Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     

    SEARCH DEV MECHANIC

    TOOLS YOU CAN USE

    advertisement


    by: cprogramming.com

    Implementing Modulus

    Written by RoD

    Modulus is a C++ function with many uses. Perhaps the most common use is finding whether or not a variable is odd or even. Modulus can also be used to find multiples of a number. Modulus works by dividing and returning a remainder, if any, of the calculation. This may seem a little confusing to you at the moment, and thatÕs perfectly normal.

    Modulus is represented in C++ by the Ō%Ķ symbol. IÕm going to show you a sample program that uses the Modulus function, and then explain it piece by piece, as I think that is the best way to make sense of what I am telling you.

    Example:
    #include <iostream>
    using namespace std;
    int main()
    {
    int some_value;
    std::cout << "Enter a value: ";
    std::cin >> some_value;
    if ( some_value % 2 == 0 )
    {
    std::cout << some_value << " is an even number" << endl;
    }
    else
    {
    std::cout<< val << " is an odd number" <<<< endl;
    }
    }
    

    Ok everything up to the if statement should make plenty of sense to you by now, and if it doesnÕt you need to consult another tutorial. IÕm going to explain this if statement and what its doing because thatÕs the chunk of this program that pertains to the subject as hand.

    if ( some_value % 2 == 0 ) :ĘThis line may look a bit confusing at first, but in a moment its going to make plenty of sense! If the user given value modulus two gives no remainder, then the user given value is even. What this means is that the value given to us by the user, divided by two, had no remainder, which makes it even.

    Example:
    some_value = 4
    4 % 2 == 2
    
    2 is an even number, there is no remainder. Now consider this:
    some_value = 3
    3 % 2 == 1.5
    

    1.5 is odd, it has a remainder. Does it make more sense now? Hopefully it does and you have benefit from this lesson. I look forward to helping you in the future. Feel free to contact me via the message boards as RoD or via my email at Silent_Death17@hotmail.com.

    -----

    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

    More Web Development Articles
    More By Developer Shed

       

    WEB DEVELOPMENT ARTICLES

    - On Page SEO for New Domains
    - Improve Your Site`s Speed
    - Safari Books Online Review
    - Creating an Estore From the Ground Up
    - Most Common SEO Mistakes Developers Make
    - Making the Most of Your Titles and Meta Desc...
    - Five Ways Using Flash Can Damage Your Site
    - A Web Designer`s Guide to Colors
    - Use Webstarts to Create a Free Site
    - More Than Just Looks. How Your Web Design C...
    - How to Design Content Pages
    - Mint Review
    - Make Your WordPress Website Look Professional
    - How to Create a Mobile Web Site
    - Meta Tags: Still Useful?

    Developer Shed Affiliates

     



    © 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap