Hello! I am beginner trying to learn c++. Yesterday I wrote a simple calculator program, but when I run it I get strange results. Here is the code:
Code:
#include <iostream>
using namespace std;
int main()
{
int br1;
int br2;
cout << "Enter first number: ";
cin >> br1;
cout << "Enter second number: ";
cin >> br2;
cout << endl << "Results: " << endl << endl;
cout << "First + second number = " << br1 + br2 << endl;
cout << "First - second number = " << br1 - br2 << endl;
cout << "First * second number = " << br1 * br2 << endl;
cout << "First / second number = " << br1 / br2 << endl;
cin.ignore();
cin.get();
}
When I compile and run the program, I get this (Red color is what I enter):
Enter first number: 34593874
Enter second number: 34532224535
Results:
First + second number = -2112889775
First - second number = -2112889773
First * second number = -34593874
First / second number = 0
Process returned 0 (0x0) execution time : 8.596 s
Press any key to continue.
How could I, with adding and multiplying two positive numbers, get a negative number?
Should it not be that 34593874 + 34532224535 = 34566818409 and not -2112889775 ?
It is probably silly question, but I don't get it
PS. I used Code Blocks compiler.