1

我写了一个日历代码,但我有一些杂散错误。这是我的代码:

#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;
}

另一部分是打印结果。它向我显示了下面的错误

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 = year – (14 – month)/12;

我不知道错误是什么意思,有人可以帮助我吗?谢谢!!

4

2 回答 2

5

错误是在您的代码中报告 bytes \342\200\223(以八进制表示)。这些字节构成了EN DASH的 UTF-8 编码。这是英文文本中用于范围(如六月至八月)或关系(如悉尼至洛杉矶航班)的字符。C++ 编译器通常接受的减号字符是与 ASCII 兼容的HYPHEN-MINUS,它是 QWERTY 键盘上可用的字符。

看起来您从某处复制并粘贴了此代码,并且在此行中有错误的减法字符:

Y = year – (14 – )month)/12;

还要注意不应该存在的额外括号。也许你想要:

Y = year - (14 - month) / 12;
于 2013-03-21T14:26:28.740 回答
1

我认为您在该行)的第二个之后有一个额外的-

Y = year – (14 – )month)/12;

应该:

Y = year – (14 – month)/12;
于 2013-03-21T14:27:34.447 回答