gpt4 book ai didi

c - c 中函数切换中的 ";" token 错误之前预期为 "{"

转载 作者:行者123 更新时间:2023-11-30 19:55:01 24 4
gpt4 key购买 nike

我正在学习 C 语言作为我的第一语言。我正在使用 gcc 代码块编译器。我试图使用 switch-case观看视频后的发言。我收到一个错误,;之前预计 {声明 token 。我尝试过但找不到任何错误。谁能帮我解决这个问题吗?

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

最佳答案

关键字是switch,而不是Switch。您使编译器误认为您正在调用函数,因此在行后缺少语句终止符,如下所示:

Switch(choice);

关于c - c 中函数切换中的 ";" token 错误之前预期为 "{",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42249209/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com