All pastes #59912 Raw Edit

gia des ayto

public c v1 · immutable
#59912 ·published 2006-05-30 13:15 UTC
rendered paste body
#include <stdio.h>#define N 20#define M 5void getdata(struct candidate *cnd);float read19(struct candidate *cand);float read20(struct candidate *cand);struct candidate{        int code,test;        char name[N];        float v1,v2;        int category;};main(){        struct candidate cand;        FILE *fp,*f;        float sum19,sum20,sumepit=0;        char c;        getdata(&cand);        sum19=read19(&cand);        printf("%f\n",sum19);        sum20=read20(&cand);        printf("%f\n",sum20);        fp=fopen("epitPE20.txt","a+");        while(c=getc(fp)!=EOF)        {                if(c=='\n')                {                        sumepit++;                }        }        fprintf(fp,"Pososto epitixias twn PE20: %f",sumepit*100/sum20);        fclose(fp);        fp=fopen("epitPE19.txt","a+");        while(c=getc(fp)!=EOF)        {                if(c=='\n')                {                        sumepit++;                }        }        printf("%d\n",sumepit);        fprintf(fp,"Pososto epitixias twn PE19: %f",(float)sumepit*100/(float)sum19);                printf(fp,"Pososto epitixias twn PE19: %f",(float)sumepit*100/(float)sum19);        fclose(fp);        system("pause");}void getdata(struct candidate *cnd){        int i,j;        FILE *fp,*f;        fp=fopen("inPE19.txt","w");        f=fopen("inPE20.txt","w");        for(i=0;i<M;i++)        {                do                {                        printf("Dwse tin katigoria: ");                        scanf("%d",&cnd->category );                }                while(cnd->category!=1 && cnd->category!=2);                if(cnd->category==1)                {                        printf("Dwse ton kwdiko: ");                        scanf("%d",&cnd->code);                        fprintf(fp,"%d",cnd->code);                        fprintf(fp," ");                        printf("Dwse epitheto: ");                        scanf("%s",cnd->name);                        fprintf(fp,"%s",cnd->name);                        for(j=strlen(cnd->name);j<N;j++)                        {                                fprintf(fp," ");                        }                        do                        {                                printf("Dwse ton prwto vathmo: ");                                scanf("%f",&cnd->v1);                        }                        while(cnd->v1<0 || cnd->v1>100);                        fprintf(fp,"%f",cnd->v1);                        fprintf(fp," ");                        do                        {                                printf("Dwse ton deftero vathmo: ");                                scanf("%f",&cnd->v2);                        }                        while(cnd->v2<0 || cnd->v2>100);                        fprintf(fp,"%f",cnd->v2);                        fprintf(fp," ");                        fprintf(fp,"%d",cnd->category);                        fprintf(fp,"\n");                }                else                {                        printf("Dwse ton kwdiko: ");                        scanf("%d",&cnd->code);                        fprintf(f,"%d",cnd->code);                        fprintf(f," ");                        printf("Dwse epitheto: ");                        scanf("%s",cnd->name);                        fprintf(f,"%s",cnd->name);                        for(j=strlen(cnd->name);j<N;j++)                        {                                fprintf(f," ");                        }                        do                        {                                printf("Dwse ton prwto vathmo: ");                                scanf("%f",&cnd->v1);                        }                        while(cnd->v1<0 || cnd->v1>100);                        fprintf(f,"%f",cnd->v1);                        fprintf(f," ");                        do                        {                                printf("Dwse ton deftero vathmo: ");                                scanf("%f",&cnd->v2);                        }                        while(cnd->v2<0 || cnd->v2>100);                        fprintf(f,"%f",cnd->v2);                        fprintf(f," ");                        fprintf(f,"%d",cnd->category);                        fprintf(f,"\n");                }        }        fclose(fp);        fclose(f);}float read19(struct candidate *cand){        FILE *fp,*f,*f2;        float sum=0;        fp=fopen("inPE19.txt","r");        f=fopen("epitPE19.txt","w");        f2=fopen("apotPE19.txt","w");        while(fscanf(fp,"%d",&cand->code)!=EOF)        {                sum++;                fscanf(fp,"%s",cand->name);                fscanf(fp,"%f",&cand->v1);                fscanf(fp,"%f",&cand->v2);                fscanf(fp,"%d",&cand->category);                if(cand->v1>=55)                {                        if(cand->v2>=55)                        {                                if((cand->v1+cand->v2)/2>=60)                                {                                  fprintf(f,"%d%s%f%f%d\n",cand->code,cand->name,cand->v1,cand->v2,cand->category);                                  printf("pernaei\n");                                }                                else                                {                                        fprintf(f2,"%d%s%f%f%d\n",cand->code,cand->name,cand->v1,cand->v2,cand->category);                                        printf("mikros mesos oros");                                }                        }                        else                        {                                fprintf(f2,"%d%s%f%f%d\n",cand->code,cand->name,cand->v1,cand->v2,cand->category);                                printf("mikros b vathmos\n");                        }                }                else                {                        fprintf(f2,"%d%s%f%f%d\n",cand->code,cand->name,cand->v1,cand->v2,cand->category);                        printf("mikros a vathmos");                }        }        fclose(fp);        fclose(f);        fclose(f2);        return sum;}float read20(struct candidate *cand){        FILE *fp,*f,*f2;        float sum=0;        f=fopen("epitPE20.txt","w");        fp=fopen("inPE20.txt","r");        f2=fopen("apotPE20.txt","w");        while(fscanf(fp,"%d",&cand->code)!=EOF)        {                sum++;                fscanf(fp,"%s",cand->name);                fscanf(fp,"%f",&cand->v1);                fscanf(fp,"%f",&cand->v2);                fscanf(fp,"%d",&cand->category);                if(cand->v1>=55)                {                        if(cand->v2>=55)                        {                                if((cand->v1+cand->v2)/2>=60)                                {                                  fprintf(f,"%d%s%f%f%d\n",cand->code,cand->name,cand->v1,cand->v2,cand->category);                                }                                else                                {                                        fprintf(f2,"%d%s%f%f%d\n",cand->code,cand->name,cand->v1,cand->v2,cand->category);                                }                        }                        else                        {                                fprintf(f2,"%d%s%f%f%d\n",cand->code,cand->name,cand->v1,cand->v2,cand->category);                        }                }                else                {                        fprintf(f2,"%d%s%f%f%d\n",cand->code,cand->name,cand->v1,cand->v2,cand->category);                }        }        fclose(fp);        fclose(f);        fclose(f2);        printf("sum=%f",sum);        return sum;}