I've made a simple c++ program that takes in two numbers, clears the screen, and then outputs the sum of those two numbers to the terminal window. It works great. Typing 5 as the first number and 10 as the second outputs 15.
Except there's one issue. When running the program with the first number being 5 and the second being something very long, such as:
3285720358162039587169230839461283795732948567123857690,
the program doesn't output the right number, and doesn't show the correct number that the user typed either.
For example, when using the previous two numbers, the "sum" will be: -2147483644, when it should be the long number with a 5 instead of a zero on the end.
Here's my code:
#include <iostream>
int main() {
system ("clear");
int num1 = 0;
int num2 = 0;
std::cout << "What is the first number?: ";
std::cin >> num1;
std::cout << "What is the second number?: ";
std::cin >> num2;
system ("clear");
std::cout << "The sum of " << num1 << " and " << num2 << " is: " << (num1 + num2) << "\n";
}