因此,我试图创建一个日历,使用switch语句以数字方式询问用户选择的月份和日期,然后尝试使用if语句检查用户的日期输入,如果匹配,则显示日期。
运行时,即使我输入了星期一的日期,它也始终打印星期日。我想念什么?
这是我的代码
void UserInput()
{
cout << "\nPlease enter a numerical value of a month e.g. May=5, December=12: \n";
cin >> Month;
cout << "\nPlease enter a Date: \n";
cin >> Date;
}
void MagicCalendar()
{
switch(Month)
{
case 1:
if(Date == 6 || 13 || 20 || 27)
{
cout << " It's Sunday!!!";
break;
}
if(Date == 7 || 14 || 21 || 28 ) <-- the problem is probably here idk if its the operand or the if statement itself
{
cout << " It's a MOFO MONDAY GO KYS NOW!";
break;
}
else if(Date ==)
{
cout << " It's a Tuesday and kinda like a monday but yeah...";
break;
}
else if(Date ==)
{
cout << " It's Wednesday and I know that you can feel it!";
break;
}
else if(Date ==)
{
cout << " It's a THURSDAY!! getting warmer :D";
break;
}
else if(Date ==)
{
cout << " It's FRIDAY!! GO GET SHITFACED YOU DESERVE IT :D";
break;
}
else if(Date ==)
{
cout << " It's SATURDAY BABY! go cry in a corner while suffering from Hungover...";
break;
}
break;
}
}
if(Date == 6 || 13 || 20 || 27)
语法错误
正确:
if(Date == 6 || Date == 13 || Date == 20 || Date == 27)
类似于代码中的其他行。