Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Sep 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    remainder output

    #include <cstdlib>
    #include <iostream.h>



    void main()
    {
    double num;
    double num2;

    cout<<" Good Day!!\n";

    cout<<"Please enter a number = ";
    cin>>num;
    cout<<"Another one to be divided= ";
    cin>>num2;
    cout<<"answer is = "<<num / num2;
    cout<<"\n" ;

    }

    my prob is i want to the remainder only.. ex. 18/5 then the remainder is 3.. can someone revise my code??tnx guys

  • #2
    Regular Coder BWiz's Avatar
    Join Date
    Mar 2006
    Location
    Sol System
    Posts
    471
    Thanks
    7
    Thanked 21 Times in 21 Posts
    Use the modulus operator.

    Code:
    int main(void) {
      int rem = 18%5;
      cout << rem << endl;
    }
    BWiz :: Happy Coding!
    2006
    2007 2008 2009
    2010 2011
    Irrational numbers make no sense.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •