簡體   English   中英

C 中的嵌套 IF else 語句

[英]Nested IF else statement in C

我似乎無法在我的程序中找到問題,它說“錯誤:輸入末尾的預期聲明或語句”

我想了解更多關於這個錯誤的信息

#include<stdio.h>

int main()
{
    float Math, English, Science, Fundamentals, per;
    
    printf("Enter GPA of 4 subject\n");
    scanf("%f %f %f %f", &Math, &English, &Science, &Fundamentals);
    
    per = (Math + English + Science + Fundamentals) / 4.0;
    
    if(per >= 5)
    {
        printf("Your GWA is: 75\n");
    }
    else
    {
        if(per >= 3)
        {    
            printf("Your GWA is: 75\n");
        }
        else
        {
            if(per >= 2)
            {
                printf("Your GWA is: 85\n");
            }
            else
            {
                if(per >= 1)
                {
                      printf("Your GWA is: 100\n");
                }
            }
        }        
        
     return 0;
    }

根據圖中可以看到,你在else部分寫了return 0 ,而你應該寫main function 的末尾。

編輯:

您必須添加的第一行

#include <iostream>

而且在return 0之前你還需要}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM