C++ Help needed - some weird buy/error ..

Discussion in 'Programming' started by ActiveFrost, Mar 7, 2009.

  1. #1
    So - I've 2 numbers and result ( num1 * num2 ) ! Why I keep getting crazy numbers ( 2*3 is 6 not 72 :mad: ) ?

    [​IMG]
     
    ActiveFrost, Mar 7, 2009 IP
  2. hillord

    hillord Well-Known Member

    Messages:
    2,211
    Likes Received:
    59
    Best Answers:
    0
    Trophy Points:
    140
    #2
    can u try other than multiply... does it still output 72?
     
    hillord, Mar 8, 2009 IP
  3. NuLLByTe

    NuLLByTe Active Member

    Messages:
    382
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    80
    #3
    
    result = (num1 * num2);
    
    Code (markup):
    should be after
    
    num1 = 2;
    num2 = 3;
    
    Code (markup):
    Simplier you could just type:
    
    int num1 = 2;
    int num2 = 3;
    int result = (num1 * num2);
    
    Code (markup):
     
    NuLLByTe, Mar 8, 2009 IP
  4. ActiveFrost

    ActiveFrost Notable Member

    Messages:
    2,072
    Likes Received:
    63
    Best Answers:
    3
    Trophy Points:
    245
    #4
    num1 - num2 ( 2 - 3 ) = -37 :eek:

    Tried everything - all the time I get something crazy !
     
    ActiveFrost, Mar 8, 2009 IP
  5. NuLLByTe

    NuLLByTe Active Member

    Messages:
    382
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    80
    #5
    Did you read my post?
     
    NuLLByTe, Mar 8, 2009 IP
  6. ActiveFrost

    ActiveFrost Notable Member

    Messages:
    2,072
    Likes Received:
    63
    Best Answers:
    3
    Trophy Points:
    245
    #6
    Did what you said, did what others said ( google ) - still the same ! Will try to reinstall my stuff ( compiler, etc. ) ..
     
    ActiveFrost, Mar 8, 2009 IP
  7. shils

    shils Peon

    Messages:
    7
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    num1 and num2 are assigned values after definition of the variables...
    crazy no.s will occur everytime bcoz compiler uses garbage values since at the time of calculation (num1*num2)
    the variables are not having the values.


    do rply if it solved ur problem....
    thankx...
     
    shils, Mar 8, 2009 IP
    ActiveFrost likes this.
  8. ActiveFrost

    ActiveFrost Notable Member

    Messages:
    2,072
    Likes Received:
    63
    Best Answers:
    3
    Trophy Points:
    245
    #8
    Problem solved ! Thanks to everyone who tried to help :)
     
    ActiveFrost, Mar 8, 2009 IP
  9. hillord

    hillord Well-Known Member

    Messages:
    2,211
    Likes Received:
    59
    Best Answers:
    0
    Trophy Points:
    140
    #9
    so what's the problem? is it your include files or compiler?
     
    hillord, Mar 9, 2009 IP
  10. peterCx

    peterCx Peon

    Messages:
    34
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    result = (num1 * num2);

    After declare variable
     
    peterCx, Mar 10, 2009 IP