Thread: function question

  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    5

    Question function question

    I would like to know how to code division addition and subtraction. I learned how to code multiplication from tutorial 4 or 5 I cannot remember which please help im just currious.

  2. #2
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398
    Code:
    X = A + B;
    X = A - B;
    X = A * B;
    X = A / B;
    Note that your "unknown" goes on the left hand side.
    The equal sign is the assignment operator. You are assigning the value on the right to the variable on the left.

    [EDIT -
    And, be careful when dividing integers 1 / 2 won't give the right answer, because the result will be a truncated integer. 1.0 / 2.0 will result in a floating point answer.
    Last edited by DougDbug; 08-31-2005 at 02:52 PM.

  3. #3
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034
    Code:
    int number1 = 5;
    int number2 = 10;
    int number3;
    
    number3 = 1 + 1; // = 2
    number3 = number1 + number2; // = 5 + 10 = 15
    number3 = number2 / number1; // = 10 divided by ( / ) 5 = 2
    number3 = number2 - number1; // = 10 - 5 = 5
    number3 = number3 * 2; // = the previously stored number ( 5 ) x 2 = 10
    number3 = number3 + 5; // = the previously stored number ( 10 ) + 5 = 15;
    number3 += 5; // = the previously stored number ( 15 ) + 5 = 20 (  number3 += is just like saying number3 = number3 +
    The colored text is past the // symbols and therefor a comment, and not part of the code, just text to explain the line.
    Last edited by Dae; 08-31-2005 at 02:50 PM.
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

  4. #4
    Registered User
    Join Date
    Aug 2005
    Posts
    5
    thanks a bunch! I will give those a shot thx.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. CreateThread() function question
    By chiefmonkey in forum C++ Programming
    Replies: 5
    Last Post: 05-15-2009, 07:52 AM
  2. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 11:45 AM
  3. Bisection Method function value at root incorrect
    By mr_glass in forum C Programming
    Replies: 3
    Last Post: 11-10-2005, 09:10 AM
  4. Change this program so it uses function??
    By stormfront in forum C Programming
    Replies: 8
    Last Post: 11-01-2005, 08:55 AM
  5. Replies: 3
    Last Post: 03-04-2005, 02:46 PM