While Loop Trouble Help Needed

Hello. I have two issues with my code.

The first one is that I'm trying to use a while function to terminate the program when the word "none" is typed for the operation.

The second one is that I keep getting the "floating point exception (core dumped)" error every time that I set that "The denominator cannot be 0 while performing a division operation." for the dividing function.

Can anyone see what's wrong with 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
33
34
35
36
37
38
#include <iostream>
using namespace std;

int main(){ //main function

	char operation;
    int num1;
    int num2;

    cout << "Enter operator either + or - or * or /: ";
    cin >> operation;
    cout << "Enter the first integer: ";
    cin >> num1;
    cout << "Enter the second integer: ";
    cin >> num2;
    while ((integer = cin.get()))
    switch(operation) {
        case '+':
            cout << num1+num2;
            break;
        case '-':
            cout << num1-num2;
            break;
        case '*':
            cout << num1*num2;
            break;
        case '/':
            cout << num1/num2;
            if (num2 < 1){ 
    			cout << "The denominator cannot be 0 while performing a division operation." << endl;
    		}
            break;
        default:
            /* If operator is other than +, -, * or /, error message is shown */
            cout << "The operation is invalid.";
            break;
            }
    return 0;
Last edited on
Line 16 looks like its from another program. It makes no sense here. Delete that line.
Topic archived. No new replies allowed.