I am new to c++. I made a calculator and i "build and run" it and it worked perfectly. then I tried to run the program that was created by the compiler and when I put in the numbers and hit enter the program just shuts down without showing the answer can someone help me?
I use codeblock
#include <iostream>
#include <limits>
using namespace std;
int num1, num2, result;
int main()
{
cout << "Welcome! please enter a number!" << endl;
The problem is when you ask the user for a number, s/he must insert a number and press ‘enter’.
As a consequence, in the input buffer there will be a number plus the character ‘enter’ ('\n').
When you ‘std::cin’ the buffer into an integer variable, there’s no room for the following '\n'.
So it may happen that you need to explicitely tell std::cin to ignore one character after having read numbers.
My personal advice is to avoid system() as long as you can.