我正在学习C语言作为我的第一语言。我正在使用gcc代码块编译器。我在观看视频后尝试使用switch-case
语句。我收到;
语句令牌之前预期{
的错误。我试过但找不到任何错误。有人可以帮我解决这个问题吗?
#include<stdio.h>
#include<conio.h>
int main()
{
int b,sum,avg,multi,choise,s[5],a[3];
printf("Please select any option\n");
printf("1. I want addition of numbers.\n");
printf("2. I want to take average of numbers.\n");
printf(" 3. I want the multiplication table of a number.\n");
printf("4. Exit\n");
Switch(choise)
{
case 1:
printf("You have selected the 1st option,\n");
printf("Please enter any 5 numbers you want to add.\n");
gets(s);
sum=s[0]+s[1]+s[2]+s[3]+s[4];
printf("The sum of the numbers you entered is %d",sum);
break;
case 2:
printf("You have selected the 2nd option,\n");
printf("Enter any 3 numbers to take average of them.\n");
gets(a);
avg=a[0]+a[1]+a[2]/3;
printf("The average of the three numbers you entered is %d",avg);
break;
case 3:
printf("You have selected the 3rd option,\n");
printf("Please enter the number you want the multiplication table of,\n");
scanf("%d",&multi);
for(b=1;b<=10;b++)
{
printf("%d * %d = %d\n",multi,b,multi*b);
}
break;
default:
printf("invalid input.\n");
break;
}
}
答案 0 :(得分:7)
关键字为switch
,而非Switch
。您混淆了编译器,认为您正在调用函数,因此在行之后缺少语句终止符,如下所示:
Switch(choice);