problem with a reapeating cout

ok so i am having trouble with a reapeated word in my c++ program everything works except that a cout reapeates itself like this.

math bios: add
enter 2 numbers to add
5
5
5+5=10
math bios:
math bios: //i dont want this second one.

also when i type stop it says returning to main... and stays in the math function? any help is appreciated.

here is the code
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
int math(){
    while(x=1){

cout << endl << "math.bios: ";
    getline (cin, operation);
    if      (operation == "add"){
        cout << "enter 2 numbers to add.\n";
        cin >> x >> y;
        cout << x << "+" << y <<"=" << (x+y);
    }
    else if (operation == "subtract"){
        cout << "enter 2 numbers to subtract.\n";
        cin >> x >> y;
        cout << x << "-" << y <<"=" << (x-y);
    }
    else if (operation == "multiply"){
        cout << "enter 2 numbers to multiply.\n";
        cin >> x >> y;
        cout << x << "*" << y <<"=" << (x*y);
    }
    else if (operation == "divide"){
        cout << "enter 2 numbers to divide.\n";
        cin >> x >> y;
        cout << x << "/" << y <<"=" << (x/y);
    }
    else if (operation == "stop"){
        cout << "returning to main...";
    (x==0);
    }

    }
}
line 28 x = 0; //or 'break;'

About the double cout, I'm guessing that the input stream still has some junk in it from the last time cin was called. So line 5 ends up not waiting for new input until the loop runs an extra time. Try placing cin.ignore(80,'\n'); just before line 5 and see if that fixes it.
You've got the assignment and comparison operators mixed up too. Line 2 should be while (x == 1) and line 28 should be x = 1;

soranz' guess is correct.
Topic archived. No new replies allowed.