简体   繁体   English

C 中的嵌套 IF else 语句

[英]Nested IF else statement in C

I can't seem to locate the problem in my program where it says, "error: expected declaration or statement at the end of input"我似乎无法在我的程序中找到问题,它说“错误:输入末尾的预期声明或语句”

I would like to learn more about this mistake我想了解更多关于这个错误的信息

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

According to what can be seen in the picture, you wrote return 0 inside the else section, while you should write the end of the main function.根据图中可以看到,你在else部分写了return 0 ,而你应该写main function 的末尾。

Edit:编辑:

First line you have to add您必须添加的第一行

#include <iostream>

And also before return 0 you need }而且在return 0之前你还需要}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM