#include <iostream>
#include <string>
using namespace std;
int main()
{
// Declare a variable to store an integer
int InputNumber;
cout << "Enter an integer: ";
// store integer given user input
cin >> InputNumber;
// The same with text i.e. string data
cout << "Enter your name: ";
string InputName;
cin >> InputName;
cout << InputName << " entered " << InputNumber << endl;
return 0;
}
The above program produces wrong output if I enter some string for InputNumber , whats happening there , I assume that the memory allocated to Inputnumbe is overwritten but is that the problem? A sample output is also given.
correct output
Enter an integer: 123
Enter your name: asdf
asdf entered 123
wrong output
Enter an integer: qwert
Enter your name: entered 0