C级边界程序,潜在运行时错误?

C级边界程序,潜在运行时错误?,c,gcc,runtime-error,ansi,C,Gcc,Runtime Error,Ansi,本课程的目的是确定考试中获得一定分数所需的最低分数。例如,用户将进入测试5 10 10项目9 10 15,这意味着他们得到了5/10的测试,它值他们分数的10%,项目9/10值他们分数的15% 我写了这个程序,并在信息中硬编码,但现在我要求用户输入信息,我无法通过for循环中的打印。有人能帮忙吗?我认为运行这个程序需要很长时间,当我让程序运行大约半个小时时,我设法让它打印出“总计”,但仅此而已 编辑:是预期的输出。这就是我现在得到的 #包括 #包括 #包括 #定义P 50 #定义H3 65 #

本课程的目的是确定考试中获得一定分数所需的最低分数。例如,用户将进入测试5 10 10项目9 10 15,这意味着他们得到了5/10的测试,它值他们分数的10%,项目9/10值他们分数的15%

我写了这个程序,并在信息中硬编码,但现在我要求用户输入信息,我无法通过for循环中的打印。有人能帮忙吗?我认为运行这个程序需要很长时间,当我让程序运行大约半个小时时,我设法让它打印出“总计”,但仅此而已

编辑:是预期的输出。这就是我现在得到的


#包括
#包括
#包括
#定义P 50
#定义H3 65
#定义H2b 70
#定义H2a 75
#定义H180
#定义最大值10
typedef char name_t[MAX];
类型定义结构{
姓名;
双标记;
双出式;
双倍重量;
双倍总数;
}评估;
int main(int argc,字符**argv){
评估对象[最大值];
/*---------------------------------------------------------------------------*/    
printf(“\n\n按此顺序输入信息,并用空格分隔\n”);
printf(“输入所有信息后,按enter\n”);
printf(“(包括检查,但输入标记位为0):\n”);
printf(“名称标记超出重量\n\n”);
/*---------------------------------------------------------------------------*/    
inti,n;
双倍合计=0;
/*---------------------------------------------------------------------------*/    
对于(i=0;(scanf(“%s%lf%lf%lf”,&Subject[i]。名称,&Subject[i]。标记,&Subject[i]。outof,&Subject[i]。权重))==4;i++){
如果(i==0){
printf(“名称\t标记\tOut of \tWeight\tTotal”);
}
受试者[i]。总计=((受试者[i]。分数/受试者[i]。超出)*受试者[i]。体重);
printf(“\n%s\t%2.1lf\t%2.1lf\t%2.2lf\t%2.2lf”,主题[i]。名称,主题[i]。标记,
受试者[i]。超出,受试者[i]。体重,受试者[i]。总计);
}
/*---------------------------------------------------------------------------*/       
n=i;
对于(i=0;i H3&&(总计+结果-1)H2b&(总计+结果-1)H2a&(总计+结果-1)H1&(总计+结果-1)H1&(总计+结果-1)
请查看以下更改,我发现它对我来说运行良好: 在计算总计之后,您应该设置
i=1
,并且在for循环中应该有一个中断条件,如
if(i>10)break我做了一些其他更改。请运行代码并查看。我看到正在执行双算术的int,这可能不是字段预期的结果。请检查以下链接:

#包括
#包括
#包括
#定义P 50
#定义H3 65
#定义H2b 70
#定义H2a 75
#定义H180
#定义最大值10
typedef char name_t[MAX];
类型定义结构{
姓名;
双标记;
双出式;
双倍重量;
双倍总数;
}评估;
int main(int argc,字符**argv){
评估对象[最大值];
双级=0,结果=0;
/*---------------------------------------------------------------------------*/    
printf(“\n\n按此顺序输入信息,并用空格分隔\n”);
printf(“输入所有信息后,按enter\n”);
printf(“(包括检查,但输入标记位为0):\n”);
printf(“名称标记超出重量\n\n”);
/*---------------------------------------------------------------------------*/    
inti,n;
双倍合计=0;
/*---------------------------------------------------------------------------*/    
对于(i=0;i H2b&&(总计+结果-1)H2a&(总计+结果-1)H1&(总计+结果-1)H1&(总计+结果-1)
1)
for(i=0;i
for(i=0;i
2)
result=(年级/科目[i-1]。超出)*科目[i-1].weight;
i
是错误的值。@BLUEPIXY谢谢!修复了这些错误,但是它们对运行时都没有任何帮助。这个问题让我一整天都很紧张!知道它为什么在做它正在做的事情还是不做的事情吗?@LollyW你在for循环中有失败条件,如
scanf(%s%lf%lf),&Subject[i].name,&Subject[i]。mark,&Subject[i]。outof,&Subject[i]。weight))==4
为什么不干脆
i@Gopi我学到了这个框架,所以for循环会一直工作,直到用户停止输入数据。我发现的问题是for循环工作正常,但是for循环之外似乎没有任何东西工作,这让我很困惑,因为当我硬编码信息时,它都工作了。这个框架我我已经使用了很多次,没有任何问题。@LollyW错误是运行时错误。编译器错误不是错误。另外,请包括
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define P 50
#define H3 65
#define H2b 70
#define H2a 75
#define H1 80
#define MAX 10

typedef char name_t[MAX];
typedef struct {
    name_t name;
    double mark;
    double outof;
    double weight;
    double total;
} assesment_t;


int main(int argc, char **argv){
    assesment_t Subject[MAX];
    /*---------------------------------------------------------------------------*/    
    printf("\n\nEnter information in this order separated by a space\n");
    printf("When all info entered, press enter\n");
    printf("(Include exam but enter the Mark bit as 0):\n");
    printf("Name    Mark    OutOf   Weight\n\n");
    /*---------------------------------------------------------------------------*/    
    int i, n;
    double total = 0;
    /*---------------------------------------------------------------------------*/    
    for(i = 0;(scanf("%s %lf %lf %lf", &Subject[i].name,&Subject[i].mark,&Subject[i].outof,&Subject[i].weight)) == 4;i++) {

        if(i == 0) {
            printf("Name\tMark\tOut of\tWeight\tTotal");   
        }

        Subject[i].total = ( (Subject[i].mark/Subject[i].outof) * Subject[i].weight );

        printf("\n%s\t%2.1lf\t%2.1lf\t%2.2lf\t%2.2lf", Subject[i].name, Subject[i].mark,
            Subject[i].outof, Subject[i].weight, Subject[i].total);
    }
    /*---------------------------------------------------------------------------*/       
    n = i;
    for( i = 0; i <= n; i++) {
        total += Subject[i].total;
    }
    printf("\nTotal: %3.2lf\n\n", total);
    /*---------------------------------------------------------------------------*/        
    double grade, result;
    for( grade = 23; grade <= 60; grade++) {
        result = (grade / Subject[i-1].outof) * Subject[i-1].weight;
        if(total + result > P && (total + result - 1) < P)
            printf("minimum of %2.0lf is needed for FAIL\n", grade);
        else if(total + result > H3 && (total + result - 1) < H3)
            printf("minimum of %2.0lf is needed for P\n", grade);
        else if(total + result > H2b && (total + result - 1) < H2b)
            printf("minimum of %2.0lf is needed for H3\n", grade);
        else if(total + result > H2a && (total + result - 1) < H2a)
            printf("minimum of %2.0lf is needed for H2b\n", grade);
        else if(total + result > H1 && (total + result - 1) < H1)
            printf("minimum of %2.0lf is needed for H2a\n", grade);
        else if(total + result > H1 && (total + result - 1) < H1)
            printf("minimum of %2.0lf is needed for H1\n", grade);
        else
            ;
    }
    /*---------------------------------------------------------------------------*/
    return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define P 50
#define H3 65
#define H2b 70
#define H2a 75
#define H1 80
#define MAX 10 

typedef char name_t[MAX];
typedef struct {
    name_t name;
    double mark;
    double outof;
    double weight;
    double total;
} assesment_t;


int main(int argc, char **argv){
    assesment_t Subject[MAX];
       double grade=0, result=0;
    /*---------------------------------------------------------------------------*/    
    printf("\n\nEnter information in this order separated by a space\n");
    printf("When all info entered, press enter\n");
    printf("(Include exam but enter the Mark bit as 0):\n");
    printf("Name    Mark    OutOf   Weight\n\n");
    /*---------------------------------------------------------------------------*/    
    int i, n;
    double total = 0;
    /*---------------------------------------------------------------------------*/    
    for(i = 0;i<10;i++) {
scanf("%s %lf %lf %lf", &Subject[i].name,&Subject[i].mark,&Subject[i].outof,&Subject[i].weight);
        if(i == 0) {
            printf("Name\tMark\tOut of\tWeight\tTotal");   
        }

        Subject[i].total = ( (Subject[i].mark/Subject[i].outof) * Subject[i].weight );

        printf("\n%s\t%2.1lf\t%2.1lf\t%2.2lf\t%2.2lf", Subject[i].name, Subject[i].mark,
            Subject[i].outof, Subject[i].weight, Subject[i].total);
    }
    /*---------------------------------------------------------------------------*/       
    n = i;
    for( i = 0; i < n; i++) {
        total += Subject[i].total;
    }

    printf("\nTotal: %3.2lf\n\n", total);
    /*---------------------------------------------------------------------------*/        
 i= 1;
         while(i<=10){
for( grade = 23; grade <= 60; grade++) {
    result = (grade / Subject[i-1].outof) * Subject[i-1].weight;
    printf("%lf\n",result);
    if((total + result) > P && (total + result - 1) < P)
        printf("minimum of %2.0lf is needed for FAIL\n", grade);
    else if((total + result) > H3 && (total + result - 1) < H3)
        printf("minimum of %2.0lf is needed for P\n", grade);
    else if((total + result) > H2b && (total + result - 1) < H2b)
        printf("minimum of %2.0lf is needed for H3\n", grade);
    else if((total + result) > H2a && (total + result - 1) < H2a)
        printf("minimum of %2.0lf is needed for H2b\n", grade);
    else if((total + result) > H1 && (total + result - 1) < H1)
        printf("minimum of %2.0lf is needed for H2a\n", grade);
    else if((total + result) > H1 && (total + result - 1) < H1)
        printf("minimum of %2.0lf is needed for H1\n", grade);
        else
        printf("None of the above cases pass\n");

}
i++;
 }
    printf("Out of Loop\n");
    /*---------------------------------------------------------------------------*/
    return 0;
}