[英]Invalid user-defined conversion: C++ error
I am making a (very) simple calculator program in C++ using Code::Blocks as my IDE. 我正在使用Code :: Blocks作为我的IDE在C ++中制作一个(非常)简单的计算器程序。 I am experiencing a couple of errors in my program.
我的程序遇到了几个错误。 Please take a look at my code and tell me what the mistake is.
请查看我的代码,并告诉我错误是什么。 Thank you.
谢谢。
#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;
}
Errors: 错误:
error: invalid user-defined conversion from 'std:: basic_ostream<char>' to
'int' [-fpermissive]
error: expected unqualified-id before 'while'
I started learning C++ just four days ago, so please appreciate the fact that I don't know much about the errors. 我是四天前才开始学习C ++的,所以请欣赏我对错误了解不多的事实。 Also, I am unsure whether i need to include limits, so please tell me in the comments below.
另外,我不确定是否需要包含限制,因此请在下面的评论中告诉我。
int main
is not a function declaration change it to int main
不是函数声明将其更改为
int main()
and sum()
needs a semicolon. 并且
sum()
需要分号。 and in if(ascii_value==113)
, ascii_value
is defined nowhere in the code 在
if(ascii_value==113)
,在代码中的任何地方都没有定义ascii_value
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.