| | |
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:
Solved Threads: 0
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
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
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
C Syntax (Toggle Plain Text)
#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...
*Voted best profile in the world*
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
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.
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?
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
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
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
•
•
Join Date: May 2007
Posts: 24
Reputation:
Solved Threads: 0
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
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
•
•
Join Date: May 2007
Posts: 24
Reputation:
Solved Threads: 0
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);
}
}
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);
}
}
Is assignment the average or just another grade? If it's the average then you need to sum them across all of the students:
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.
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.
C Syntax (Toggle Plain Text)
{ 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 ); }
•
•
•
•
What is that:-
double dummy = sin(0.0); //goodwin patch here!
double d = dummy;
dummy=d;
supposed to do?
New members chased away this month: 3
Here's how you would do it with the average being just another grade:
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.
C Syntax (Toggle Plain Text)
{ 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 ); }
New members chased away this month: 3
![]() |
Other Threads in the C Forum
- Previous Thread: Class help needed
- Next Thread: Initialising Video Modes
| Thread Tools | Search this Thread |
Tag cloud for C
adobe ansi api array arrays asterisks binarysearch calculate centimeter char convert copyimagefile copypdffile cprogramme creafecopyofanytypeoffileinc createcopyoffile csyntax directory drawing dynamic fflush file fork forloop frequency getlasterror givemetehcodez graphics gtkgcurlcompiling hacking hardware highest homework i/o inches incrementoperators infiniteloop interest kernel km lazy linked linkedlist linux linuxsegmentationfault list lists locate logical_drives match matrix microsoft motherboard multi mysql number open opendocumentformat opensource owf pattern pdf performance pointer pointers posix problem probleminc program programming pyramidusingturboccodes radix recursion recv repetition research scanf scheduling scripting segmentationfault send sequential shape socketprograming spoonfeeding stack standard string strings structures student systemcall testautomation turboc unix user variable voidmain() wab windows.h






