1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

C program not printing

  1. May 29, 2016 #1
    1. The problem statement, all variables and given/known data
    one teacher wants to know the % of fail and aproved of the class of "N" number of students, the minimun qualification to aprove is "7", write a program that reads the students qualifications, and then the program says the number of aproved and failed students and the % of failed and aproved students.


    2. Relevant equations
    the code is in spanish my natal languaje but i am puting the translations of the code..
    alumnos=students
    reprobados=failed
    aprobados=aproved
    calification=qualification or the average sum of examns
    indice=% of failed and aproved students




    3. The attempt at a solution
    its almost done but the program dont show the "how much students failed the curse"

    here is my code
    Code (C):

    #include<stdio.h>
    int main(){
    int x,a[5],ia,ir,repro=0,apro=0;
    for(x=0;x<5;x++){
         printf("ingrese la calificacion del alumno %d:\n",x+1);
         scanf("%d",&a[x]);
    }
    for(x=0;x<5;x++){
         if(a[x]>7){
         apro++;}
    }
    for(x=6;x>0;x--){
         if(a[x]<7){
         repro--;}
    }
    printf("\n\nLos alumnos aprobados son %d\n",apro);
    printf("\n\nLos alumnos reprobados son %d\n",repro);
    ia=(2*apro)*10;
    printf("\n\nEl indice de alumnos aprobados es del %d %%\n",ia);
    ir=100-ia;
    printf("\n\nEl indice de alumnos reprobados es del %d %%\n",ir);
    return 0; }
     
    <<Mentor's note: post edited for clarity. Please use code tags.>>
     
    Last edited by a moderator: May 29, 2016
  2. jcsd
  3. May 29, 2016 #2

    DrClaude

    User Avatar

    Staff: Mentor

    Your program doesn't work for arbitrary N.

    Could you please give more details as to what doesn't work?

    The index of a is out of bounds.
     
  4. May 29, 2016 #3
    Ok more detailed, my program when runs display every thing exept for how much students failed the curse, i mean the program do the calculations for % of failed students but dont display the number of failed students
     
  5. May 29, 2016 #4
    i think its more a little error than a serious code break error
     
  6. May 29, 2016 #5

    DrClaude

    User Avatar

    Staff: Mentor

    I have no problem running your code.
     
  7. May 29, 2016 #6

    rcgldr

    User Avatar
    Homework Helper

    Fixes noted in comments. I'm not sure if there are any other issues.

    Code (C):

    #include<stdio.h>
    int main(){
    int x,a[5],ia,ir,repro=0,apro=0;
    for(x=0;x<5;x++){
         printf("ingrese la calificacion del alumno %d:\n",x+1);
         scanf("%d",&a[x]);
    }
    for(x=0;x<5;x++){
         if(a[x]>7){
             apro++;}
    }
    for(x=5;x>0;x--){        /* changed 6 to 5 */
         if(a[x]<=7){        /* changed < to <= */
             repro--;}
    }
    printf("\n\nLos alumnos aprobados son %d\n",apro);
    printf("\n\nLos alumnos reprobados son %d\n",repro);
    ia=(2*apro)*10;
    printf("\n\nEl indice de alumnos aprobados es del %d %%\n",ia);
    ir=100-ia;
    printf("\n\nEl indice de alumnos reprobados es del %d %%\n",ir);
    return 0; }
     
    The second two loops could be combined:

    Code (Text):

    for(x=0;x<5;x++){
         if(a[x]>7){
             apro++;}
         else{
             repro--;}
    }
     
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted