944,089 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Marked Solved
  • Views: 3820
  • C RSS
You are currently viewing page 1 of this multi-page discussion thread
May 3rd, 2007
0

Averaging and grading program in C

Expand Post »
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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
cyberman111 is offline Offline
24 posts
since May 2007
May 3rd, 2007
0

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

  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...
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
May 3rd, 2007
0

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

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.
Reputation Points: 15
Solved Threads: 9
Junior Poster
cutepinkbunnies is offline Offline
143 posts
since Apr 2006
May 3rd, 2007
0

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

>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?
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
May 3rd, 2007
0

Re: Averaging and grading program in C

Next time try a more meaningful title. I edited the current one to make some sense out of it...
Super Moderator
Featured Poster
Reputation Points: 3241
Solved Threads: 719
Failure as a human
~s.o.s~ is offline Offline
8,873 posts
since Jun 2006
May 3rd, 2007
0

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

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
cyberman111 is offline Offline
24 posts
since May 2007
May 3rd, 2007
0

Re: Averaging and grading program in C

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);
}

}
Reputation Points: 10
Solved Threads: 0
Newbie Poster
cyberman111 is offline Offline
24 posts
since May 2007
May 3rd, 2007
0

Re: Averaging and grading program in C

What is that:-
double dummy = sin(0.0); //goodwin patch here!
double d = dummy;
dummy=d;

supposed to do?
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
May 3rd, 2007
0

Re: Averaging and grading program in C

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.
Quote ...
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.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
May 3rd, 2007
0

Re: Averaging and grading program in C

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.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: Class help needed
Next Thread in C Forum Timeline: Initialising Video Modes





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC