The Easiest Way to Save and Share Code Snippets on the web

AP1Q1

c

posted: May, 8th 2012 | jump to bottom

#include <stdio.h>
#include <stdlib.h>
 
int main()
{
    // -- Initializers --
    int crdt[3];
    float m, Nota[2][3];
    int i, j;
 
    // -- User entry scan routine --
    for(i = 0; i < 3; i++)
    {
        printf("Informe as informacoes sobre a cadeira %d:\n", i+1);
        for(j = 0; j < 2; j++)
        {
            do
            {
                printf("Nota %d: ", j+1);
                scanf("%f", &Nota[j][i]);
                if((Nota[j][i]>10)||(Nota[j][i]<0)) printf("Entrada invalida, tente novamente");
            } while((Nota[j][i]>10)||(Nota[j][i]<0));
        }
        do
        {
            printf("Creditos: ");
            scanf("%d", &crdt[i]);
            if((crdt[i]>10)||(crdt[i]<0)) printf("Entrada invalida, tente novamente");
        } while((crdt[i]>10)||(crdt[i]<0));
        printf("\n");
    }
 
    // -- Calculation --
    m = 0;
    for(i = 0; i < 3; i++)
    {
        m += ((Nota[0][i]+Nota[1][i])/2)*crdt[i];
    }
    m /= (crdt[0]+crdt[1]+crdt[2]);
    // -- ERROR --
 
    // -- Result --
    printf("%f;", m);
    if(m >= 7) printf(" \"Parabens!\"");
    else if (m > 3) printf(" \"Que tal itensificar os estudos no proximo semestre?\"");
    else printf(" \"Cuidado com o jubilamento!\"");
 
    return 0;
}
17 views