Results 1 to 5 of 5

Thread: c++ question

  1. #1
    Senior Member
    Join Date
    Jun 2004

    c++ question

    i do not know why but when I try and calculate 4.2 million and 5000 it gives me -884901888. i am using dev-c++ as my compiler.
    here is my code

    #include <cstdlib>
    #include <iostream>

    using namespace std;

    int main(int argc, char *argv[])
    int blocks = 2400000;
    int weight = 5000;
    int total;

    total = blocks * weight;
    cout << "Weight is: " << total << endl;

    return EXIT_SUCCESS;

  2. #2
    Junior Member Phenom's Avatar
    Join Date
    Sep 2009
    Los Angeles - CA

    Could there be a possibility that the number of bits used to represent a memory location of type *int* may not hold the result of the integer multiplication being performed?

    I am not sure, but, I myself am asking that question.


  3. #3
    Senior Member
    Join Date
    Jun 2004
    i can not believe i didnt think of that thank you.

  4. #4
    Junior Member
    Join Date
    Aug 2009
    You need to use long or double or something like that. I believe that int only goes from -32767 to 32766 (or something along those lines). So, once it hits the maximum, it's starting over at the minimum and continuing with the rest.

    Don't quote me on the range, as I don't have my programming books right here. But it's definitely lower than what you're trying. So long would be the right choice (I believe)

    Have a great day

  5. #5
    Senior Member
    Join Date
    Jun 2004
    yea you need to use a double, long also dose not go high enough at least that's what oneof my books says.

    scratch what i said before I remembered how to format the out_put
    Last edited by Riot; September 14th, 2009 at 11:38 PM.

Similar Threads

  1. Question Time
    By jm459 in forum Tech Humor
    Replies: 1
    Last Post: April 14th, 2004, 01:41 PM
  2. Maximum performance question
    By Fasheezy in forum Hardware
    Replies: 5
    Last Post: February 5th, 2004, 03:25 PM
  3. Test Your General Linux Knowledge
    By smirc in forum AntiOnline's General Chit Chat
    Replies: 6
    Last Post: May 13th, 2002, 04:35 PM
  4. Test Your Knowledge of Redhat?
    By smirc in forum AntiOnline's General Chit Chat
    Replies: 3
    Last Post: May 13th, 2002, 03:24 AM
  5. Question Bout AntiPoint Assignment
    By NetSyn in forum Site Feedback/Questions/Suggestions
    Replies: 15
    Last Post: May 8th, 2002, 01:45 AM

Posting Permissions

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

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.