0

Пробую скомпилировать код:

// Calculator

#include <iostream>

using namespace std;

int main()
{
    float num1, num2, result;
    char action;

    cout << "What are we going to do? (+, -, *, /): ";
    cin >> action;

    cout << "Enter 1-st number: ";
    cin >> num1;
    cout << "Enter 2-nd number: ";
    cin >> num2;

    if (action == "+") {
        result = num1 + num2;
        cout << "Result is: " << result;
    }

    if (action == "-") {
        result = num1 - num2;
        cout << "Result is: " << result;
    }

    return 0;
}

Выдает ошибку:

error: ISO C++ forbids comparison between pointer and integer [-fpermissive]

Подскажите, как исправить?

2
  • на какой строчке?
    – user176262
    18 мар 2020 в 19:41
  • У Вас action имеет тип char, а Вы сравниваете его с строкой. Используйте одинарные кавычки.
    – isnullxbh
    19 мар 2020 в 7:35

1 ответ 1

2
if (action == '+') {

...

if (action == '-') {

...

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.