c - C中嵌套if else语句的程序

标签 c

我有一个非常基本的 C 程序用于计算成绩,但它运行不正常,请任何人帮忙,这里是代码

#include <stdio.h> 
#include <math.h> 

int main()  
{ 
        int test1 ,test2,assignment1 , assignment2; 

        printf("Please enter the first test mark: ");      
        scanf("%f", &test1); 
        printf("You entered: %f \n", test1);

        printf("Please enter the second test mark: ");      
        scanf("%f", &test2); 
        printf("You entered: %f \n",test2); 

        printf("Please enter the first assignment mark: ");      
        scanf("%f", &assignment1); 
        printf("You entered: %f \n", assignment1); 

        printf("Please enter the second assignment mark: ");      
        scanf("%f", &assignment2); 
        printf("You entered: %f \n", assignment2); 

/* Now using nested ifs the program will use the calculate the average of the entered numbers and will 
   determine what the final mark is for the student */ 

        if ((test1+test2+assignment1+assignment2)/4 == '100>80') 
          printf ("You got an A! \n");
        else 
          if ((test1+test2+assignment1+assignment2)/4 == '79>70') 
          printf ("You got a B! \n"); 
        else 
          if ((test1+test2+assignment1+assignment2)/4 == '69>60') 
             printf ("You got a C! \n");
        else 
          if ((test1+test2+assignment1+assignment2)/4 == '59>50') 
             printf ("You got a D! \n");        
        else 
          if ((test1+test2+assignment1+assignment2)/4 == '49>0') 
            printf ("You got an F! \n"); 
        else 
          if (test1,test2 == '50>0') 
              printf ("You got an F! \n"); 
        else 
          if ((assignment1, assignment2) == '50>0') 
              printf ("You got a  ! \n");                
        else 
           printf ("INVALID MARK! \n"); 
      return 0;
}

这里是输出。 enter image description here

最佳答案

int test1,test2,赋值1,赋值2;更改为

float 测试1,测试2,赋值1,赋值2;

关于c - C中嵌套if else语句的程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32671162/

相关文章:

c - 指令缓存加载和驱逐规则

c - 如何读取 C 中函数参数的字符串?

C - 如何从标准输入或文件内存保存读取字符串行

c - 编译哪个阶段会报 "symbol defined multiple times"?

c - C 中的 Excel 文本函数

php - WSO2 WSF/PHP 安装问题(需要 C 开发人员帮助)

c - 虚拟环境内存泄漏怎么办?

c - C 型鞭尾压力表

c++ - C++ 中的 strtok() 模拟

c - 如何将目录添加到 autoconf 的库搜索路径