繁体   English   中英

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

[英]Invalid user-defined conversion: C++ error

我正在使用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 ++的,所以请欣赏我对错误了解不多的事实。 另外,我不确定是否需要包含限制,因此请在下面的评论中告诉我。

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

int main()

并且sum()需要分号。 if(ascii_value==113) ,在代码中的任何地方都没有定义ascii_value

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM