cin.get()

i made a very simple calculator and when i press enter to receive the result it doesnt work. can someone tell me what i did wrong?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include "stdafx.h"

#include <iostream>
using namespace std;

int main ()
{
	int a;
		int b;

		cout << "Choose your first number";
		cin >> a;

		cout << "Choose your second number";
		cin >> b;
		
		cout << "The result is"<<a*b;
		cout << "Press any key to exit";
		
		cin.get();
		return 0;
}
Add this before cin.get() (you'll have to include climits):
cin.ignore(LONG_MAX,'\n');
ty dude it works
Chinese:你为什么要用cin.get()呢?用cin.get()必须要包含头文件climits
Enghlish:Why u must use cin.get()?If u must ,you must include the head file climits.
Why must you post on a solved topic?
"ty dude it works". See? It's been solved, and it worked. Helios told him the solution. And Helios already said to include climits...
#include<iostream>
using namespace std;
int main()
{
int first_num,second_num,result;

cout<<"ENTER 1ST NUMBER : ";
cin>>first_num;
cout<<endl;
cout<<"ENTER 2ND NUMBER : ";
cin>>second_num;
cout<<endl;
result=first_num*second_num;
cout<<"THE RESULT IS :"<<result;
return 0;
}
Topic archived. No new replies allowed.