Averaging and grading program in C

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

Join Date: May 2007
Posts: 24
Reputation: cyberman111 is an unknown quantity at this point 
Solved Threads: 0
cyberman111 cyberman111 is offline Offline
Newbie Poster

Averaging and grading program in C

 
0
  #1
May 3rd, 2007
at the end of this program we have to add the average of all the students* add and divide by 3* also put a ** next to student who have over 95 % both thses should be displayed at the end
so ANYONE dare to try

#include <stdio.h>
#include <math.h>
/* AUTHOR :: your name here */
struct student
{
long id;
char name[26];
float assignment;
float quiz1;
float quiz2;
};
void main(void)
{
struct student st[5];
int x=0;
double dummy = sin(0.0); //goodwin patch here!
double d = dummy;
dummy=d;
for (x=0; x<5; x++)
{
printf("\nPlease input ID (or a zero to quit) : ");
scanf("%ld", &st[x].id);
if (st[x].id == 0)
break;
while (getchar() != '\n') //goodwin patch here!
continue;
printf("\nplease input name: ");
gets(st[x].name);
printf("\nPlease input assignment grade: ");
scanf("%f", &st[x].assignment);
printf("\nPlease input Quiz 1 grade: ");
scanf("%f", &st[x].quiz1);
printf("\nPlease input Quiz 2 grade: ");
scanf("%f", &st[x].quiz2);
}
printf("\n ID \t NAME \t AVERAGE");
printf("\n------------------------------\n");
for (x=0; x<25; x++)
{
if (st[x].id == 0)
break;
printf("\n %ld ", st[x].id);
printf("\t %s ", st[x].name);
printf("\t %.1f ", st[x].assignment); //print average instead and *** when >95
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,273
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 378
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: to all programmers lets see how good u r my lil bro got this problem and we cant do

 
0
  #2
May 3rd, 2007
  1. #include <stdio.h>
  2. #include <math.h>
  3. /* AUTHOR :: your name here */
  4. struct student
  5. {
  6. long id;
  7. char name[26];
  8. float assignment;
  9. float quiz1;
  10. float quiz2;
  11. };
  12. void main ( void ) //int main?
  13. {
  14. struct student st[5];
  15. int x = 0;
  16. double dummy = sin ( 0.0 ); //goodwin patch here!
  17. double d = dummy;
  18. dummy = d;
  19. for ( x = 0; x < 5; x++ )
  20. {
  21. printf ( "\nPlease input ID (or a zero to quit) : " );
  22. scanf ( "%ld", &st[x].id );
  23. if ( st[x].id == 0 )
  24. break;
  25. while ( getchar() != '\n' ) //goodwin patch here!
  26. continue;
  27. printf ( "\nplease input name: " );
  28. gets ( st[x].name );
  29. printf ( "\nPlease input assignment grade: " );
  30. scanf ( "%f", &st[x].assignment );
  31. printf ( "\nPlease input Quiz 1 grade: " );
  32. scanf ( "%f", &st[x].quiz1 );
  33. printf ( "\nPlease input Quiz 2 grade: " );
  34. scanf ( "%f", &st[x].quiz2 );
  35. }
  36. printf ( "\n ID \t NAME \t AVERAGE" );
  37. printf ( "\n------------------------------\n" );
  38. for ( x = 0; x < 25; x++ )
  39. {
  40. if ( st[x].id == 0 )
  41. break;
  42. printf ( "\n %ld ", st[x].id );
  43. printf ( "\t %s ", st[x].name );
  44. printf ( "\t %.1f ", st[x].assignment );

>void main
should be int main

>gets
Use fgets instead

> double dummy = sin ( 0.0 ); //goodwin patch here!
What's the purpose of sin...
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 143
Reputation: cutepinkbunnies is an unknown quantity at this point 
Solved Threads: 8
cutepinkbunnies's Avatar
cutepinkbunnies cutepinkbunnies is offline Offline
Junior Poster

Re: to all programmers lets see how good u r my lil bro got this problem and we cant do

 
0
  #3
May 3rd, 2007
I don't understand what is so difficult here. Couldn't you just insert conditional formatting to determine the grade and print its corresponding printf? (I'm a VB guy)

if st.avg >= 95
printf(student grade with bling)
else
printf(student grade)
endif

Don't know if this is what you were looking for, but hopefully it helps.

Jon
Last edited by cutepinkbunnies; May 3rd, 2007 at 4:29 pm.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,823
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 748
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Senior Bitch

Re: to all programmers lets see how good u r my lil bro got this problem and we cant

 
0
  #4
May 3rd, 2007
>so ANYONE dare to try
You're making it sound like this program is difficult and it takes courage to complete when in reality it's trivial and takes little more than sufficient boredom to churn out a bit of code. So are you trying to get us to finish your homework for you? Or do you have a question that you'd like answered?
New members chased away this month: 3
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,642
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 472
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: Averaging and grading program in C

 
0
  #5
May 3rd, 2007
Next time try a more meaningful title. I edited the current one to make some sense out of it...
I don't accept change; I don't deserve to live.

Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 24
Reputation: cyberman111 is an unknown quantity at this point 
Solved Threads: 0
cyberman111 cyberman111 is offline Offline
Newbie Poster

Re: to all programmers lets see how good u r my lil bro got this problem and we cant

 
0
  #6
May 3rd, 2007
lol its not homework school is done lastweek
I just had this problem left over and couldt seem to get the avg of all the students also the *** beside all who scored over 95

i did this program from scratch but cant get it done and it is really annoying me i really want to know how the outcome looks
so if anyoen could assist in this and show me the codeing it will be nice considering i am only 15 and this is making my head hurt
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 24
Reputation: cyberman111 is an unknown quantity at this point 
Solved Threads: 0
cyberman111 cyberman111 is offline Offline
Newbie Poster

Re: Averaging and grading program in C

 
0
  #7
May 3rd, 2007
ok lets see
so far i got this as your alredy know now where do i start, like how do I total the avg for all students.

struct student
{
long id;
char name[26];
float assignment;
float quiz1;
float quiz2;
};

void main(void)
{
struct student st[5];
int x=0;

double dummy = sin(0.0); //goodwin patch here!
double d = dummy;
dummy=d;

for (x=0; x<5; x++)
{
printf("\nPlease input ID (or a zero to quit) : ");
scanf("%ld", &st[x].id);

if (st[x].id == 0)
break;

while (getchar() != '\n') //goodwin patch here!
continue;

printf("\nplease input name: ");
gets(st[x].name);

printf("\nPlease input assignment grade: ");
scanf("%f", &st[x].assignment);

printf("\nPlease input Quiz 1 grade: ");
scanf("%f", &st[x].quiz1);

printf("\nPlease input Quiz 2 grade: ");
scanf("%f", &st[x].quiz2);
}

printf("\n ID \t NAME \t AVERAGE");
printf("\n------------------------------\n");

for (x=0; x<25; x++)
{
if (st[x].id == 0)
break;

printf("\n %ld ", st[x].id);

printf("\t %s ", st[x].name);

printf("\t %.1f ", st[x].assignment);
}

}
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,273
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 378
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: Averaging and grading program in C

 
0
  #8
May 3rd, 2007
What is that:-
double dummy = sin(0.0); //goodwin patch here!
double d = dummy;
dummy=d;

supposed to do?
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,823
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 748
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Senior Bitch

Re: Averaging and grading program in C

 
0
  #9
May 3rd, 2007
Is assignment the average or just another grade? If it's the average then you need to sum them across all of the students:
  1. {
  2. double sum = 0;
  3.  
  4. for (x=0; x<5; x++)
  5. {
  6. if (st[x].id == 0)
  7. break;
  8.  
  9. printf("\n %ld ", st[x].id);
  10. printf("\t %s ", st[x].name);
  11. printf("\t %.1f ", st[x].assignment );
  12.  
  13. sum += st[x].assignment;
  14. }
  15.  
  16. printf ( "Total average: %f\n", sum / 5 );
  17. }
If it's not the average, then you need to calculate the average by adding the assignment grade and both quizes together, then dividing by 3 before adding that result to the sum.
What is that:-
double dummy = sin(0.0); //goodwin patch here!
double d = dummy;
dummy=d;

supposed to do?
My guess is that it's a floating-point hack for the compiler. Occasionally if you use a floating-point type (especially with older compilers), you'll get an error saying "floating-point formats not linked". It looks like some clueless instructor just started doing floating-point operations until the problem went away.
New members chased away this month: 3
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,823
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 748
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Senior Bitch

Re: Averaging and grading program in C

 
0
  #10
May 3rd, 2007
Here's how you would do it with the average being just another grade:
  1. {
  2. double sum = 0;
  3.  
  4. for (x=0; x<5; x++)
  5. {
  6. double avg = ( st[x].assignment + st[x].quiz1 + st[x].quiz2 ) / 3;
  7.  
  8. if (st[x].id == 0)
  9. break;
  10.  
  11. printf("\n %ld ", st[x].id);
  12. printf("\t %s ", st[x].name);
  13. printf("\t %.1f ", avg );
  14.  
  15. sum += avg;
  16. }
  17.  
  18. printf ( "Total average: %f\n", sum / 5 );
  19. }
And I would appreciate it if you would keep related questions to the thread instead of sending me PMs. I watch the threads carefully, so PMing me isn't going to result in a faster response.
New members chased away this month: 3
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the C Forum
Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC