Új hozzászólás Aktív témák

  • cellpeti

    nagyúr

    üdv!

    Nekem lenne egy progim,ami bekéri a motor teljesítményét lóerőben,utánna meg be kell kérni a hengerűrtartalmat ccm-be.
    Ha a teljesítménynél üres sort adunk be,akkor ki kell lépnie. De ha nem számot adtál be,akkor is dobjon egy hiba üzit,mind a teljesítménynél,mind a hengerűrtartalomnál. Addig meg van,hogy bekéje mind2t.

    #include<stdio.h>
    #include<stdlib.h>
    #include<ctype.h>

    int getline(char s[],int lim){
    int i,c;
    for (i=0;i<lim && (c=getchar())!=EOF && c!='\n';++i)
    s[i]=c;
    s[i]='\0';
    while (c!=EOF && c!='\n')
    c=getchar();
    return (i);
    }

    int ell(char s[])
    {
    int i,h,ok=1;
    h=strlen(s);
    for(i=0;i<h;i++) { if (!isdigit(s[i])) ok=0;}
    return ok;
    }

    void main(void)
    {
    int ok,loe,kobc;
    char loero[10],ccm[10];


    do
    {
    ok=0;
    printf("Kerem a teljesitmenyet loeroben: ");
    getline(loero,10);
    ok=ell(loero);
    loe=0;
    loe=atoi(loero);
    }while(ok!=1);

    do
    {
    ok=0;
    printf("\nKerem a motor hengerurtartalmat kobcentiben: ");
    getline(ccm,10);
    ok=ell(ccm);
    kobc=0;
    kobc=atoi(ccm);

    }while(ok!=1);

    printf("\nA motor loereje: %dLE\n",loe);
    printf("\nA motor hengerurtartalma: %dccm\n\n",kobc);
    }

Új hozzászólás Aktív témák