Pausing a calculator program

Can someone explain "cin.get()" and "cin.ignore()" to me? I don't understand how it works and i want to pause this program without using system ("pause"). Sorry if i sound stupid, this is a noob talking here.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include "stdafx.h"
#include <iostream>
using namespace std;

int main()
{
        double num1, num2, result;
        int operation;
        cout << "Enter a number\n";
        cin >> num1;
        cout << "Enter another number\n";
        cin >> num2;
        cout << "Enter 1 for addition, 2 for subtraction, 3 for multiplication and 4 for division\n";
        cin >> operation;
        if (operation < 1 || operation > 4)
        {
            cout << "sorry, your input is not valid, please try again.\n";
		}
		else    if (operation == 1)
		{
			result = num1 + num2;
		}
		else    if (operation == 2)
		{
			result = num1 - num2;
		}
		else    if (operation == 3)
		{
			result = num1 * num2;
		}
		else    if (operation = 4)
		{
			result = num1 / num2;
		}
		else
			cout << "hacker, gtfo\n";
		cout << "And your answer is " << result << endl;
		cin.ignore();
	
		return 0;
}
cin leaves the newline character in the stream. Adding cin.ignore() to the next line clears/ignores the newline from the stream.

This is used mainly with combinations of cin and getline. I can't think of any examples but over time you will find them if you use getline and cin together.

Take a look at this:
http://www.cplusplus.com/forum/articles/6046/
Topic archived. No new replies allowed.