help me with this code

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Closed Thread

Join Date: Jul 2008
Posts: 41
Reputation: raja289 is an unknown quantity at this point 
Solved Threads: 0
raja289 raja289 is offline Offline
Light Poster

help me with this code

 
0
  #1
Jul 9th, 2008
  1. #include<stdio.h>
  2. #include<string.h>
  3. float avg(float);
  4. main()
  5. {
  6. FILE *p[2];
  7. int k,students=10,subjects=4,i,j,id_number,date_of_birth,fail=0;
  8. float marks[100],total=0,avg;
  9. char name[30],course_enrolled[30],filename[10];
  10. for(i=1;i<=2;i++)
  11. {
  12. printf("filename");
  13. scanf("%s",&filename);
  14. p[i]=fopen(filename,"w");
  15. printf("Enter Name of Student\n",p[i]);
  16. fscanf(stdin,"%s",&name,p[i]);
  17. printf("Enter Course In Which Student Is Enrolled\n",p[i]);
  18. fscanf(stdin,"%s",&course_enrolled,p[i]);
  19. printf("Enter ID Number Of %s Enrolled in Course %s\n",name,course_enrolled,p[i]);
  20. fscanf(stdin,"%d",&id_number,p[i]);
  21. printf("Enter Date Of Birth Of %s Enrolled in Course %s and\n ID-Number is %d\n",name,course_enrolled,id_number,p[i]);
  22. fscanf(stdin,"%d",&date_of_birth,p[i]);
  23. for(j=1;j<=4;j++)
  24. {
  25. printf("Enter Marks for Subject %d for Student %s\n",j,name);
  26. fscanf(stdin,"%f",&marks[j]);
  27. total=total+marks[j];
  28. if(marks[j]<50)
  29. fail=fail+1;
  30. else
  31. continue;
  32. }
  33. avg=(total/400)*100;
  34. printf("AVERAGE=%f\n",avg);
  35. if(avg>=70)
  36. printf("Grade A\n");
  37. if(avg>=60&avg<70)
  38. printf("Grade B\n");
  39. else if(avg>=50&avg<60)
  40. printf("Grade C\n");
  41. else if(avg>=45&avg<50)
  42. printf("Grade D\n");
  43. else if(avg>=40&avg<45)
  44. printf("Grade E\n");
  45. else if(avg<40)
  46. printf("Fail\n");
  47. if(fail>=2)
  48. printf("Student is failed and cann;t promote\n");
  49. else
  50. continue;
  51. fclose (p[i]);
  52. }
  53. for(k=1;k<=2;k++)
  54. {
  55. printf("Input filename");
  56. scanf("%s",&filename);
  57. p[k]=fopen(filename,"r");
  58. fprintf(stdout,"NAME= %s\tCOURSE ENTITLLED= %s\t ID NUMBER= %d\t DATE OF BIRTH= %d\tAVERAGE= %f\n",name,course_enrolled,id_number,date_of_birth,avg);
  59. fclose (p[k]);
  60. }
  61. getch();
  62. }



there is a problem i cann;t save all data in a single file as well as but cann;t use array of pointers in function to save records of 10 students
Last edited by Ancient Dragon; Jul 10th, 2008 at 6:08 am. Reason: add code tags
Quick reply to this message  
Join Date: Dec 2006
Posts: 251
Reputation: ssharish2005 is on a distinguished road 
Solved Threads: 20
ssharish2005's Avatar
ssharish2005 ssharish2005 is offline Offline
Posting Whiz in Training

Re: help me with this code

 
1
  #2
Jul 9th, 2008
Pleaseeeeeeeeeeeeeeeeee use code tags and intendant the code.

ssharish
Quick reply to this message  
Join Date: Aug 2006
Posts: 319
Reputation: Luckychap is on a distinguished road 
Solved Threads: 42
Luckychap's Avatar
Luckychap Luckychap is offline Offline
Posting Whiz

Re: help me with this code

 
0
  #3
Jul 9th, 2008
  1. #include<stdio.h>
  2. #include<string.h>
  3. float avg(float);
  4. main()
  5. {
  6. FILE *p[2];
  7. int k,students=10,subjects=4,i,j,id_number,date_of_birth,fail=0;
  8. float marks[100],total=0,avg;
  9. char name[30],course_enrolled[30],filename[10];
  10. for(i=1;i<=2;i++)
  11. {
  12. printf("filename");
  13. scanf("%s",&filename);
  14. p[i]=fopen(filename,"w");
  15. printf("Enter Name of Student\n",p[i]);
  16. fscanf(stdin,"%s",&name,p[i]);
  17. printf("Enter Course In Which Student Is Enrolled\n",p[i]);
  18. fscanf(stdin,"%s",&course_enrolled,p[i]);
  19. printf("Enter ID Number Of %s Enrolled in Course %s\n",name,course_enrolled,p[i]);
  20. fscanf(stdin,"%d",&id_number,p[i]);
  21. printf("Enter Date Of Birth Of %s Enrolled in Course %s and\n ID-Number is %d\n",name,course_enrolled,id_number,p[i]);
  22. fscanf(stdin,"%d",&date_of_birth,p[i]);
  23. for(j=1;j<=4;j++)
  24. {
  25. printf("Enter Marks for Subject %d for Student %s\n",j,name);
  26. fscanf(stdin,"%f",&marks[j]);
  27. total=total+marks[j];
  28. if(marks[j]<50)
  29. fail=fail+1;
  30. else
  31. continue;
  32. }
  33. avg=(total/400)*100;
  34. printf("AVERAGE=%f\n",avg);
  35. if(avg>=70)
  36. printf("Grade A\n");
  37. if(avg>=60&avg<70)
  38. printf("Grade B\n");
  39. else if(avg>=50&avg<60)
  40. printf("Grade C\n");
  41. else if(avg>=45&avg<50)
  42. printf("Grade D\n");
  43. else if(avg>=40&avg<45)
  44. printf("Grade E\n");
  45. else if(avg<40)
  46. printf("Fail\n");
  47. if(fail>=2)
  48. printf("Student is failed and cann;t promote\n");
  49. else
  50. continue;
  51. fclose (p[i]);
  52. }
  53. for(k=1;k<=2;k++)
  54. {
  55. printf("Input filename");
  56. scanf("%s",&filename);
  57. p[k]=fopen(filename,"r");
  58. fprintf(stdout,"NAME= %s\tCOURSE ENTITLLED= %s\t ID NUMBER= %d\t DATE OF BIRTH= %d\tAVERAGE= %f\n",name,course_enrolled,id_number,date_of_birth,avg);
  59. fclose (p[k]);
  60. }
  61. getch();
  62. }


At line nos. 10, 23 and 53 CHECK your for loops.
Last edited by Luckychap; Jul 9th, 2008 at 10:39 pm.
When you think you have done a lot, then be ready for YOUR downfall.
Quick reply to this message  
Join Date: Jul 2008
Posts: 41
Reputation: raja289 is an unknown quantity at this point 
Solved Threads: 0
raja289 raja289 is offline Offline
Light Poster

Re: help me with this code

 
0
  #4
Jul 10th, 2008
http://s3.supload.com/free/lastscan-...3716.jpg/view/

here u can see the program that i need. i am really tired of working on it.
1) There is some problem with average as it adds up average marks of last students with current one.

2) i cann;t save all records in a single file !

3) can anyone modify this code with according to the question ("up there on image link").

thanks guys for reply
Quick reply to this message  
Join Date: Aug 2005
Posts: 15,672
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1502
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: help me with this code

 
0
  #5
Jul 10th, 2008
Don't double post the problem in multiple threads because it only causes confusion. I'm closing this thread so that the discussion can continue in the other thread.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Quick reply to this message  
Closed Thread

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C Forum


Views: 469 | Replies: 4
Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC