unexpected while loop

im having trouble understanding what is happening here. I would like the program to continue the loop while i input numbers or operator signs.... however to break out of the loop i have to do something bizzare like type in a letter twice..

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
42
43
44
45
46
int main()
{

    int lval =0;
    int rval = 0;


    char op;

    cin>>lval;

    if(!cin) //HOW DOE  S THIS KNOW TO WAIT FOR AN OPERATOR
        cout<<"no first hand operator";

    while(cin>>op)
    {
        cin>>rval;
        switch(op)
        {
            case '+':
                lval+=rval;
                break;
            case '-':
                lval-=rval;
                break;
            case '*':
                lval*=rval;
                break;
            case '/':
                lval/=rval;
                break;
            default:
                cout<<"answer: "<<lval;
                return 0;

        }
    }




    cin.get();
    return 0;

}
Topic archived. No new replies allowed.