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

Recommended Answers

All 17 Replies

Member Avatar for iamthwee
#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 ) //int main?
{
   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 );

>void main
should be int main

>gets
Use fgets instead

> double dummy = sin ( 0.0 ); //goodwin patch here!
What's the purpose of sin...

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

>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?

Next time try a more meaningful title. I edited the current one to make some sense out of it...

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

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

}

Member Avatar for iamthwee

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

supposed to do?

Is assignment the average or just another grade? If it's the average then you need to sum them across all of the students:

{
  double sum = 0;

  for (x=0; x<5; 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 );

    sum += st[x].assignment;
  }

  printf ( "Total average: %f\n", sum / 5 );
}

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. :icon_rolleyes:

Here's how you would do it with the average being just another grade:

{
  double sum = 0;

  for (x=0; x<5; x++)
  {
    double avg = ( st[x].assignment + st[x].quiz1 + st[x].quiz2 ) / 3;

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

    printf("\n %ld ", st[x].id);
    printf("\t %s ", st[x].name);
    printf("\t %.1f ", avg );

    sum += avg;
  }

  printf ( "Total average: %f\n", sum / 5 );
}

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.

so why do u divede by 5 not 3

also it is givin me the wrong output

i need to list the avg of all the students entered with a *** next to the ones with 95% or higher

Because there are five students. The first average taken inside of the loop is the average of a single student's three grades. The second average taken outside of the loop is the average of all five student's averages.

>also it is givin me the wrong output
What's wrong about it?

>i need to list the avg of all the students entered with a *** next to the ones with 95% or higher
We haven't gotten to that part yet. You don't write everything in one swell foop, you write a little and test a little until all of the features are added and working properly. :icon_rolleyes:

/*for (x=0; x<2; 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
} */
double sum = 0;
for (x=0; x<2; x++)
{
double avg = ( st[x].assignment + st[x].quiz1 + st[x].quiz2 ) / 3;
if (st[x].id == 0)
break;
printf("\n %ld ", st[x].id);
printf("\t %s ", st[x].name);
printf("\t %.1f ", avg );
sum += avg;
}
printf ( "\nTotal average: %f\n", sum / 3 );

hey it worked narue yo the man
i figur wat was wrong i had the tot # of student to 25 so i changed it all to 2 and it worked
now how do i place ** next to the ones with 95 %

i relized it was just a simple mistake at teh begging of the code i had set it to 25 studetns but by the time i got to the bottom i just put in a random number of students

now i am done with that how do I add ***
would it be another if statement
such as

else if

I DID ALL BYMYSELF LOL JK NARUE THANK YOU VERY MUCH YOUR GUIDENCE HELPED ALOT
LOOK AT THE OUTCOME
double sum = 0;
for (x=0; x<2; x++)
{
double avg = ( st[x].assignment + st[x].quiz1 + st[x].quiz2 ) / 3;
if (st[x].id == 0)
break;
printf("\n %ld ", st[x].id);
printf("\t %s ", st[x].name);
printf("\t %.1f ", avg );
if (avg > 95)
printf("*****");

sum += avg;
}
printf ( "\nTotal average: %f\n", sum / 3 );
}

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.