Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Switch



  • @ int result =0;
    bool ok;
    QString str = "";
    // QString opp = ui->opp->text();
    int number1 = ui->editor->text().toInt(&ok, 25);
    int number2 = ui->editor1->text().toInt(&ok, 25);
    switch (ui->opp->text().toInt(&ok,2)) {
    case '+':
    result = number1+ number2;
    ui->editor->setText(str.setNum(result));
    break;
    case '-':
    result = number1-number2;
    ui->editor->setText(str.setNum(result));
    break;
    case 'x':
    result = number1*number2;
    ui->editor->setText(str.setNum(result));
    break;
    case '/':
    result - number1 / number2;
    ui->editor->setText(str.setNum(result));
    break;
    default:
    ui->editor->setText("Marth Error");
    break;
    }@
    I want to do operation by usibg switch by my code give me errof



  • Hi, AFAIK switch only works with integer.
    What is your error message?


Log in to reply