c ++错误不能用作函数,有些杂散错误 [英] c++ error cannot be used as a function, some stray error
问题描述
我写了一个日历代码,但我有一些误差。
这是我的代码:
I have write a calendar code, but I have some stray error. Here is my code:
#include<iostream>
#include<iomanip>
using namespace std;
int main(){
int month, year, Y, M;
int day[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int FirstDayofMonth;
cout<<"please enter year!"<<endl;
cin>>year;
while(year<1600)
{
cout<<"please do not enter year less than 1600!"<<endl;
cin>>year;
}
cout<<"please enter month! (1~12)"<<endl;
cin>>month;
Y = year – (14 – month)/12;
M = month + 12 * ((14 - month) / 12) - 2;
FirstDayofMonth = (Y+Y/4-Y/100+Y/400+31*M/12+1)%7;
}
其他部分是打印结果。
,它显示下面的错误
Other part is to print the result. and it show me the error below
try.cpp:18: error: stray ‘\342’ in program
try.cpp:18: error: stray ‘\200’ in program
try.cpp:18: error: stray ‘\223’ in program
try.cpp:18: error: stray ‘\342’ in program
try.cpp:18: error: stray ‘\200’ in program
try.cpp:18: error: stray ‘\223’ in program
try.cpp: In function ‘int main()’:
try.cpp:18: error: expected `)' before ‘month’
try.cpp:18: error: ‘year’ cannot be used as a function
18: Y = (14个月)/ 12;
我不知道错误的意思,有谁可以帮助我吗?
谢谢!!
I don't know what the error mean, does anyone can help me? Thanks!!
推荐答案
错误是报告字节 \342
, \200
和 \223
(以八进制表示)。这些字节构成 ZH DASH 的UTF-8编码。这是在英语文本中使用的范围(例如6月至8月)或关系(例如悉尼 - 洛杉矶航班)中使用的字符。 C ++编译器通常接受的减号字符是与ASCII兼容的 HYPHEN-MINUS < a>,这是在QWERTY键盘上可用的字符。
The error is reporting bytes \342
, \200
, and \223
(represented in octal) in your code. These bytes make up the UTF-8 encoding of EN DASH. This is a character used in ranges (e.g. June–August) or relationships (e.g. Sydney–Los Angeles flight) in English text. The minus character typically accepted by C++ compilers is the ASCII compatible HYPHEN-MINUS, which is the character available on a QWERTY keyboard.
看起来您已从某处复制和粘贴此代码,并且在此行中有减号的错误字符:
Looks like you've copy and pasted this code from somewhere and have the wrong character for subtraction in this line:
Y = year – (14 – )month)/12;
还要注意额外的括号,不应该存在。也许你想要:
Also note the extra parenthesis that shouldn't be there. Perhaps you want:
Y = year - (14 - month) / 12;
这篇关于c ++错误不能用作函数,有些杂散错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!