为什么显示没有声明?应该怎样修改啊?

img

img

img

img


#include <stdio.h>
#include <string.h>

#define MAXS 80

int getindex( char *s );

int main()
{
int n;
char s[MAXS];

scanf("%s", s);
n = getindex(s);
if ( n==-1 ) printf("wrong input!\n");
else printf("%d\n", n);

return 0;

}

/* 你的代码将被嵌在这里 */
int getindex( char *s )
{
switch(*s)
{
case Sunday:return 0;
case Monday:return 1;
case Tuesday:return 2;
case Wednesday:return 3;
case Thursday:return 4;
case Friday:return 5;
case Saturday:return 6;
default:return -1;
}
}

case 后面必须是一个整数,或者是结果为整数的表达式,但不能包含任何变量。

建议使用if else


int getindex( char *s )
{
    if (strcmp(s, "Sunday") == 0) return 0;
    else if (strcmp(s, "Monday") == 0) return 1;
    else if  (strcmp(s, "Tuesday") == 0) return 2;
    else if  (strcmp(s, "Wednesday") == 0) return 3;
    else if  (strcmp(s, "Thursday") == 0) return 4;
    else if  (strcmp(s, "Friday") == 0) return 5;
    else if  (strcmp(s, "Saturday") == 0) return 6;
    else return -1;
}