Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I plugged in this code: #include <iostream> using namespace std; void displayMen

ID: 3738501 • Letter: I

Question

I plugged in this code:

#include <iostream>

using namespace std;

void displayMenu();

void calcSum(int, int);

void calcDiff(int, int);

void calcProduct(int, int);

void calcQuotient(int, int);

int main()
{

    int choice, num1, num2;

    while (true) {

        displayMenu();

        cout << "Enter your choice: ";

        cin >> choice;

        cout << endl
             << "Enter two numbers: ";

        cin >> num1 >> num2;

        switch (choice) {

        case 1:
            calcSum(num1, num2);

            break;

        case 2:
            calcDiff(num1, num2);

            break;

        case 3:
            calcProduct(num1, num2);

            break;

        case 4:
            calcQuotient(num1, num2);

            break;

        case 5:
            return 0;

        default:
            cout << "Please enter a valid choice" << endl;
        }
    }
}

void displayMenu()
{

    cout << "MENU" << endl;

    cout << "1. ADD" << endl;

    cout << "2. Subtract" << endl;

    cout << "3. Multiply" << endl;

    cout << "4. Divide" << endl;

    cout << "5. Quit" << endl
         << endl;
}

void calcSum(int a, int b)
{

    cout << "Result of addition is: " << a + b << endl
         << endl;
}

void calcDiff(int a, int b)
{

    cout << "Result of subtraction is: " << a - b << endl
         << endl;
}

void calcProduct(int a, int b)
{

    cout << "Result of multiplication is: " << a * b << endl
         << endl;
}

void calcQuotient(int a, int b)
{

    if (b == 0) {

        cout << "Division by 0 not allowed" << endl
             << endl;

        return;
    }

    cout << "Result of division is: " << a / b << endl
         << endl;
}

this is what i get when i run the code:

Project/Target: "Project 3 - Debug":

The compiler's setup (GNU GCC Compiler) is invalid, so Code::Blocks cannot find/run the compiler.

Probably the toolchain path within the compiler options is not setup correctly?!

Do you have a compiler installed?

Goto "Settings->Compiler...->Global compiler settings->GNU GCC Compiler->Toolchain executables" and fix the compiler's setup.

Tried to run compiler executable 'C:MinGW/bin/mingw32-gcc.exe', but failed!

Run aborted..

I don't know what i am doing wrong. I was using a Mac Book Pro but I switched to a Lenovo.

Explanation / Answer

Answer:

There is no issue with the given code. it is working fine as expected. The issue here is with your c++ compiler. mingw32-gcc.exe executable file was missing in your set up. If you want to run this code, you can run it in online compilers. Do check your C++ setup configurations.

#include <iostream>

using namespace std;

void displayMenu();

void calcSum(int, int);

void calcDiff(int, int);

void calcProduct(int, int);

void calcQuotient(int, int);

int main()
{

int choice, num1, num2;

while (true) {

displayMenu();

cout << "Enter your choice: ";

cin >> choice;

cout << endl
<< "Enter two numbers: ";

cin >> num1 >> num2;

switch (choice) {

case 1:
calcSum(num1, num2);

break;

case 2:
calcDiff(num1, num2);

break;

case 3:
calcProduct(num1, num2);

break;

case 4:
calcQuotient(num1, num2);

break;

case 5:
return 0;

default:
cout << "Please enter a valid choice" << endl;
}
}
}

void displayMenu()
{

cout << "MENU" << endl;

cout << "1. ADD" << endl;

cout << "2. Subtract" << endl;

cout << "3. Multiply" << endl;

cout << "4. Divide" << endl;

cout << "5. Quit" << endl
<< endl;
}

void calcSum(int a, int b)
{

cout << "Result of addition is: " << a + b << endl
<< endl;
}

void calcDiff(int a, int b)
{

cout << "Result of subtraction is: " << a - b << endl
<< endl;
}

void calcProduct(int a, int b)
{

cout << "Result of multiplication is: " << a * b << endl
<< endl;
}

void calcQuotient(int a, int b)
{

if (b == 0) {

cout << "Division by 0 not allowed" << endl
<< endl;

return;
}

cout << "Result of division is: " << a / b << endl
<< endl;
}

Output: