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;

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.