Solve C Program Not Printing Homework

In summary, the conversation is about a teacher asking for a program that can calculate the percentage of failed and approved students in a class of N number of students, with a minimum passing grade of 7. The code provided in Spanish is translated and discussed, with some minor errors pointed out and corrected. The program asks for the students' grades, counts the number of approved and failed students, and calculates the percentage of each.
  • #1
Mrencko
109
0

Homework Statement


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.

Homework 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

The Attempt at a Solution


its almost done but the program don't show the "how much students failed the curse"

here is my 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:
Physics news on Phys.org
  • #2
Mrencko said:
one teacher wants to know the % of fail and aproved of the class of "N" number of students,
Your program doesn't work for arbitrary N.

Mrencko said:
its almost done but the program don't show the "how much students failed the curse"
Could you please give more details as to what doesn't work?

Mrencko said:
C:
for(x=6;x>0;x--){
     if(a[x]<7){
     repro--;}
}
The index of a is out of bounds.
 
  • #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 don't display the number of failed students
 
  • #4
DrClaude said:
Could you please give more details as to what doesn't work?
i think its more a little error than a serious code break error
 
  • #5
I have no problem running your code.
 
  • #6
Fixes noted in comments. I'm not sure if there are any other issues.

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:
for(x=0;x<5;x++){
     if(a[x]>7){
         apro++;}
     else{
         repro--;}
}
 

Related to Solve C Program Not Printing Homework

1. Why is my C program not printing my homework?

There could be several reasons for this issue. Some common causes include errors in the code, incorrect or missing input, or problems with the compiler or runtime environment. It is important to carefully review your code and check for any mistakes or bugs that could be preventing the program from running correctly.

2. How do I troubleshoot my C program not printing my homework?

If your program is not printing your homework, the first step is to carefully review your code and check for any errors or mistakes. You may also want to try debugging your code using a debugger or adding print statements to help identify where the issue is occurring. Additionally, make sure you are using the correct compiler and that it is properly configured.

3. What should I do if my C program is still not printing my homework after troubleshooting?

If you have followed the troubleshooting steps and your program is still not printing your homework, it may be helpful to seek assistance from a more experienced programmer or your instructor. They may be able to provide insight or identify a problem that you may have overlooked.

4. Is there a specific format or syntax for printing homework in a C program?

Yes, there is a specific format and syntax for printing homework in a C program. In general, you will need to use the printf() or fprintf() function to print your homework to the screen or a file. It is important to use the correct format specifiers and syntax to ensure that your output is displayed correctly.

5. How can I prevent my C program from not printing my homework in the future?

To prevent your C program from not printing your homework in the future, it is important to carefully review your code and check for any mistakes or errors before running it. Additionally, make sure you are using the correct compiler and that it is properly configured. It may also be helpful to save your code frequently and make backups to avoid losing any progress.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
1
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
9
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
5
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
9
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
8
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
12
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
1K
Back
Top