Hello all, I've just started to learn C++ since I have a bit of time on my hands. I was doing an exercise, learning functions and built a multiplier (very basic, enter 2 numbers and here is the result) strange thing, if the numbers you enter are very high, I get this: the product of your two numbers is 373441392, is there a reason it's this number, anyone know?

#include <iostream>

using namespace std;

int mult ( int x, int y );

int main()
    int x;
    int y;

    cout<<"Please input two numbers to be multiplied (separated by a space) : ";
    cin>> x >> y;
    cout<<"The product of your two numbers is "<< mult ( x, y ) <<"\n";

int mult ( int x, int y )
    return x * y;
4 Years
Discussion Span
Last Post by Ancient Dragon

The reason is there is a maximum value that an integer can hold -- the maximum is declared in the header file limits.h that is supplied by your compiler. What you are seeing is called numeric overflow.

If you need bigger numbers then use a bigger integer, such as "long long", which holds about twice as many digits as an int or long. There are no standard C or C++ data types that will hold an infinite number of digits.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.