所以我要求用户提供出生日期,并根据它我将根据他们的生肖输出一个简短的句子。我似乎无法找到有关如何正确执行此操作的任何信息,或者在这种情况下我应如何继续关于switch语句。非常感谢任何帮助!
int dateOfBirth;
// initiate zodiac animals year of birth
int rat = 2008 || 1996 || 1984 || 1972 || 1960;
int ox = 2009 || 1997 || 1985 || 1973 || 1961;
int tiger = 2010 || 1998 || 1986 || 1974 || 1962;
int rabbit = 2011 || 1999 || 1987 || 1975 || 1963;
int dragon = 2012 || 2000 || 1988 || 1976 || 1964;
int snake = 2013 || 2001 || 1989 || 1977 || 1965;
int horse = 2014 || 2002 || 1990 || 1978 || 1966;
int goat = 2015 || 2003 || 1991 || 1979 || 1967;
int monkey = 2016 || 2004 || 1992 || 1980 || 1968;
int rooster = 2017 || 2005 || 1993 || 1981 || 1969;
int dog = 2019 || 2007 || 1995 || 1983 || 1971;
int pig = 2019 || 2007 || 1995 || 1983 || 1971;
// ask user for date of birth
printf("Please enter your date of birth: \n");
scanf_s("%d", &dateOfBirth);
// FORTUNE IF STATEMENTS
// im tired of these motherfluffing IF STATEMENTS ON MY MOTHERFLUFFING SCREEN!
// rat
if (dateOfBirth == 2008 || 1997 || 1984 || 1972 || 1960)
{
printf("Jerry?%d\n", rat);
}
//ox
elseif(dateOfBirth == 2009 || 1997 || 1985 || 1973 || 1961);
{
printf("Nice horns m8");
}
// tiger
elseif(dateOfBirth == 2010 || 1998 || 1986 || 1974 || 1962);
{
printf("RAAWR\n");
}
// rabbit
elseif(dateOfBirth == 2011 || 1999 || 1987 || 1975 || 1963);
{
printf("HOP HOP HOP %d", rabbit);
}
// dragon
elseif(dateOfBirth == 2012, 2000, 1988, 1976, 1964);
{
printf("RYUJIN NO KEN WO KURAE!");
}
// snake
elseif(dateOfBirth == 2013, 2001, 1989, 1977, 1965);
{
printf("Orochimaru?");
}
// horse
elseif(dateOfBirth == 2014, 2002, 1990, 1978, 1966);
{
printf("NOW WATCH ME NE- No.");
}
// goat
elseif (dateOfBirth == 2015, 2003, 1991, 1979, 1967);
{
printf("Cheese.");
}
// monkey
elseif (dateOfBirth == 2016, 2004, 1992, 1980, 1968);
{
printf("You sure you're not genetically engineered...?");
}
// rooster
elseif (dateOfBirth == 2017, 2005, 1993, 1981, 1969);
{
printf("Who needs an alarm clock amarite?");
}
// dog
elseif (dateOfBirth == 2018, 2006, 1994, 1982, 1970);
{
printf("Haha, funny doggo!");
}
// pig
else (dateOfBirth == 2019, 2007, 1995, 1983, 1971);
{
printf("I don't even like bacon.");
}
system("pause");
}
我希望我包含的代码是正确的,就像格式化一样。
编辑:elseif - >否则如果。在参数结尾处也没有分号,并且每年都添加“dateOfBirth ==”,代码现在工作正常,感谢所有输入,特别是来自莫斯科的@Vlad!
答案 0 :(得分:1)
对于初学者来说,C ++中没有elseif语句.C ++中有if
和if-else
语句。
此外,您必须删除if或if结尾处的错误分号。
条件也写得不正确。
有效的else语句可以查找例如
else if ( dateOfBirth == 2009 || dateOfBirth == 1997 || dateOfBirth == 1985 || dateOfBirth == 1973 || dateOfBirth == 1961 )
{
//...
}