C 错误:‘;其他’;没有以前的‘;如果’;但我想我使用了正确的语法

C 错误:‘;其他’;没有以前的‘;如果’;但我想我使用了正确的语法,c,if-statement,syntax,compiler-errors,C,If Statement,Syntax,Compiler Errors,我是C语言的新手,已经盯着我的(可能是糟糕透顶的)代码看了一段时间,但我不知道它到底出了什么问题 谁能检查一下我的错误:( 在中的编译器上说错误:“else”没有前面的“if” else//[突出显示] ^~~~,我已在注释[突出显示]中突出显示错误行,以帮助您搜索该行 #include <stdio.h> #include <string.h> void main() { int option; option = 0; while (optio

我是C语言的新手,已经盯着我的(可能是糟糕透顶的)代码看了一段时间,但我不知道它到底出了什么问题

谁能检查一下我的错误:(
在中的编译器上说错误:“else”没有前面的“if” else//[突出显示] ^~~~,我已在注释[突出显示]中突出显示错误行,以帮助您搜索该行

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

void main()
{
    int option;
    option  = 0;

  while (option != 10)//For option purpose
  {
    char blood_type[5],next;// blood type purpose
    char name[20];//name purpose
    int count = 1;//turn on loop(True)
    float discount, amountToBePaid, bill;
    int amount;
    int trial = 0, PIN, age;
    float mass, generate;

    printf("\n\n\t\t\t\tNational Blood Center x Tenaga Nasional Berhad Campaign");
    printf("\n\n--------------------------------------------------------------------------------------------------------------------------");
    printf("\n\t\t\t\tThank you for joining our campaign!");
    printf("\n\t\t\t\tIf you donate :");
    printf("\n\t\t\t\t ____________________________________ ");
    printf("\n\t\t\t\t|     Volume      |  Discount given  |");
    printf("\n\t\t\t\t ____________________________________");
    printf("\n\t\t\t\t| 150 ml - 300 ml |        16        |");
    printf("\n\t\t\t\t| 301 ml - 400 ml |        20        |");
    printf("\n\t\t\t\t| 401 ml - higher |        25        |");
    printf("\n\t\t\t\t ____________________________________");
    printf("\n\n ! All contributor are advise to NOT donate your blood for over 470ml");
    printf("\n\nDonator Condition:");
    printf("\n1. Aged between 18 and 60 years old (for those less than 18, written consent from parents or legal guardian is required)");
    printf("\n2. Body weight of at least 45 kg.");
    printf("\n3. In good physical and mental health with no chronic medical illness.");
    printf("\n4. Not on long term medications and has not been intoxicated by alcohol within 24 hours prior to donation.");
    
    printf("\n\nDo you wish to continue?\n"); // this part ask user if they want to continue or not
    printf("1.Yes\n");
    printf("2.Cancel");

    printf("\n\nEnter one of the above : "); //option, user are ask whether he/she wants to continue or not
    scanf("%d", &option);
    
    switch (option)// if the user wants to continue
    {

    case 1:
    printf("Enter age:"); // security measurement, the user is ask to enter the his/her age/mass for confirmed that he/she fulfill all of the recuirment
    scanf("%d", &age);
    printf("Enter mass [in two decimal place]:");
    scanf("%f", &mass);
    
     if( age >=18 && age <=60)
     if(mass > 60.00)
     {
     generate = age*mass; //a generated security code that derived from multiplication of age & mass (for increase the security measurement)
     printf("Your code is %.2f", generate); //display generated code
     }
    else 
     {
        printf("You may not fulfill all the conditions, try again later."); // if the user not fulfill all the conditions, the program will end
        return ;
     }

do
{
    printf("\nInsert the generate code:");
    scanf("%d", &PIN);
    trial++;
}while (PIN != generate && trial != 3);

if (PIN == generate) //[HIGHLIGHTED]
 
 
    printf("\nEnter your name: ");// next step to start  the program
    scanf("%s", name);
    printf("\nPlease Enter Your Blood Type: ");
    scanf("%s", blood_type);
    printf("Please enter amount of your total blood donation (in ml) :");
    scanf("%d", &amount);
    printf("Enter your current electricity bill: Rm");
    scanf("%f", &bill);
    printf("\n");
    
    printf("loading");//just a loading (no animation)
    
    int value = 5;
    
    while (value > 0)
    {
        
        printf(".");
        value--;
        
    }
    
    
   while (count == 1 )
   {
       if ((strcmp(blood_type,"A")==0)||(strcmp(blood_type,"a")==0))
       {
            printf("\nYour Blood Type is %s", blood_type);
            count = 0 ; //turn off loop (False)
       }
       else if((strcmp(blood_type,"B")==0)||(strcmp(blood_type,"b")==0))
       {
            printf("\nYour Blood Type is %s", blood_type);
            count = 0 ; //turn off loop (False)
       }
       else if((strcmp(blood_type,"AB")==0)||(strcmp(blood_type,"ab")==0))
       {
            printf("\nYour Blood Type is %s", blood_type);
            count = 0 ; //turn off loop (False)
       }
       else if((strcmp(blood_type,"o")==0)||(strcmp(blood_type,"O")==0))
       {
            printf("\nYour Blood Type is %s", blood_type);
            count = 0 ; //turn off loop (False)
       }
    else
       {
            printf("\n-------------\n");
            printf("Invalid input\n");
            printf("-------------\n");
            count = 0;//turn off loop (False)
            main();
           
        if(amount<150)
    {
            printf("\nYou have to paid: Rm%0.2f", bill);
            printf("\nDonate for over 150 ml to enjoy a discount cut!");
    }
    else
    {
        if(amount>=150 && amount<=300)
        {
        
            discount = (bill*16)/100;
            amountToBePaid = bill-discount;
            printf("\nAfter applying the discount, you have to paid: Rm%0.2f", amountToBePaid);
            
        }
        else if(amount>300 && amount<=400)
        {
           
            discount = (bill*20)/100;
            amountToBePaid = bill-discount;
            printf("\nAfter applying the discount, you have to paid: Rm%0.2f", amountToBePaid);
            
        }
        else if(amount>400 && amount<600)
        {
          
            discount = (bill*25)/100;
            amountToBePaid = bill-discount;
            printf("\nAfter applying the discount, you have to paid: Rm%0.2f", amountToBePaid);
            
        }
        printf("\nThank you %s for your contribution!", name);
     break; 


else  //[HIGHLIGHTED]
printf("\nSorry, Maximum attempt has been exceded. Please refer officer on duty." );



case 2:
     return ;

     
    default:
        printf("Invalid input\n");
        
    }
  }
}
}
}
}
#包括
#包括
void main()
{
int选项;
选项=0;
而(选项!=10)//用于选项目的
{
字符血型[5],下一步;//血型用途
字符名称[20];//名称用途
int count=1;//打开循环(True)
浮动折扣、金额准备、票据;
整数金额;
int试验=0,引脚,年龄;
浮动质量,生成;
printf(“国家血液中心x国家贝哈德运动”);
printf(“\n\n------------------------------------------------------------------------------------------------------------------------------”);
printf(“\n\t\t\t\t感谢您加入我们的活动!”);
printf(“\n\t\t\t\t如果您捐赠:”);
printf(“\n\t\t\t\t\t\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu”);
printf(“\n\t\t\t\t |数量|折扣|”);
printf(“\n\t\t\t\t\t\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu”);
printf(“\n\t\t\t\t | 150毫升-300毫升| 16毫升”);
printf(“\n\t\t\t\t | 301毫升-400毫升| 20毫升”);
printf(“\n\t\t\t\t | 401ml-更高| 25 |”);
printf(“\n\t\t\t\t\t\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu”);
printf(“\n\n!建议所有献血者不要献血超过470ml”);
printf(“\n\n默认条件:”);
printf(“\n1.年龄在18岁到60岁之间(对于18岁以下的人,需要父母或法定监护人的书面同意)”;
printf(“\n2.体重至少45 kg”);
printf(“\n3.身心健康,无慢性疾病。”);
printf(“\n4.未长期服用药物,且在捐赠前24小时内未饮酒。”);
printf(“\n\n是否继续?\n”);//此部分询问用户是否继续
printf(“1.是\n”);
printf(“2.取消”);
printf(“\n\n输入上述选项之一:”);//选项,用户将询问是否要继续
scanf(“%d”,选项(&O);
开关(选项)//如果用户要继续
{
案例1:
printf(“输入年龄:”;//安全度量,要求用户输入他/她的年龄/质量,以确认他/她完成了所有恢复
scanf(“%d”和年龄);
printf(“输入质量[小数点后两位]:”;
扫描频率(“%f”,质量(&M);
如果(年龄>=18岁和年龄60.00岁)
{
generate=age*mass;//生成的安全代码,由age和mass的乘积派生(用于增加安全度量)
printf(“您的代码是%.2f”,generate);//显示生成的代码
}
其他的
{
printf(“您可能不满足所有条件,请稍后再试。”);//如果用户不满足所有条件,程序将结束
返回;
}
做
{
printf(“\n插入生成代码:”);
scanf(“%d”和PIN);
试用++;
}while(PIN!=生成和试用!=3);
如果(PIN==生成)/[突出显示]
printf(“\n输入您的姓名:”;//启动程序的下一步
scanf(“%s”,名称);
printf(“\n请输入您的血型:”);
scanf(“%s”,血型);
printf(“请输入您的总献血量(毫升):”;
scanf(“%d”和金额);
printf(“输入您当前的电费:Rm”);
scanf(“%f”、&bill);
printf(“\n”);
printf(“加载”);//只是加载(无动画)
int值=5;
而(值>0)
{
printf(“.”);
价值--;
}
而(计数=1)
{
如果((strcmp(血型,“A”)==0)| |(strcmp(血型,“A”)==0))
{
printf(“\n您的血型是%s”,血型);
count=0;//关闭循环(False)
}
否则如果((strcmp(血型,“B”)=0)| |(strcmp(血型,“B”)=0))
{
printf(“\n您的血型是%s”,血型);
count=0;//关闭循环(False)
}
否则如果((strcmp(血型,AB)=0)|(strcmp(血型,AB)=0))
{
printf(“\n您的血型是%s”,血型);
count=0;//关闭循环(False)
}
否则,如果((strcmp(血型,o)=0)|(strcmp(血型,o)=0))
{
printf(“\n您的血型是%s”,血型);
count=0;//关闭循环(False)
}
其他的
{
printf(“\n-------------\n”);
printf(“无效输入\n”);
printf(“--------------\n”);
count=0;//关闭循环(False)
main();

if(amount=150&&amount300&&amount400&&amount //[突出显示]。

在此代码中:

        else if(amount>400 && amount<600)
        {
          
            discount = (bill*25)/100;
            amountToBePaid = bill-discount;
            printf("\nAfter applying the discount, you have to paid: Rm%0.2f", amountToBePaid);
            
        }
        printf("\nThank you %s for your contribution!", name);
     break; 


else  //[HIGHLIGHTED]

⟼请记住,保持代码尽可能有条理是非常重要的,特别是在学习和询问堆栈溢出问题时。这有助于传达结构,更重要的是,还有意图,这有助于我们快速找到问题的根源,而无需花费大量时间试图解码。这只是一堆代码,这里的缩进到处都是。当事情有条理且一致时,很容易发现语法错误。解决这个问题是解决问题的第一步。为什么这里有一个简单的
else
,然后是同一级别的
case2
。我不知道。编译器是对的,
else
完全没有业务它就在那里。为了您自己的利益,请将代码分解为函数。在
main()
中阻塞所有内容不是完成任何事情的好方法,除非您
if (amount < 600)
{
    // Write all the under-600 cases here, using `if` and `else if`.

    // Execute a printf after all code for the under-600 cases.
    printf("\nThank you %s for your contribution!", name);
}
else
{
    // Handle the 600-or-over case here.
}
break;