无效的用户定义的转换:C ++错误

时间:2019-06-16 18:50:10

标签: c++ calculator user-defined

我正在使用Code :: Blocks作为我的IDE在C ++中制作一个(非常)简单的计算器程序。我的程序遇到了几个错误。请查看我的代码,并告诉我错误是什么。谢谢。

#include <iostream>
#include <limits>
#include <conio.h>

int num1;
char Operator;
int num2;


void sum() {
    std::cin >> num1; // User inputs first number
    std::cin >> Operator; // User inputs operator
    std::cin >> num2; // User inputs second number

    // These if statements identify the operator and perform the appropriate 
    // operation

    if ( Operator == '+' ) {
        std::cout << num1 + num2;
     }

    else if ( Operator == '-' ) {
        std::cout << num1 - num2;
    }

    else if ( Operator == '*' ) {
         std::cout << num1 * num2;
    }

    else if ( Operator == '/' ) {
        std::cout << num1 / num2;
    }

    else {
        std:: cout << "Incorrect value/s entered.";
    }
}

int main {
    std::cout << "Press q to quit the program.";

    while(1) {
        sum()

        if(ascii_value==113) { // For Q
            break;
        }
    }

    return 0;
}

错误:

error: invalid user-defined conversion from 'std:: basic_ostream<char>' to 
'int' [-fpermissive]
error: expected unqualified-id before 'while'

我是四天前才开始学习C ++的,所以请欣赏我对错误了解不多的事实。另外,我不确定是否需要包含限制,因此请在下面的评论中告诉我。

1 个答案:

答案 0 :(得分:2)

int main不是函数声明,将其更改为

int main()

sum()需要分号。 并且在if(ascii_value==113)中,ascii_value在代码中没有定义

相关问题