Operating System - HP-UX
1757070 Members
2023 Online
108858 Solutions
New Discussion юеВ

Re: Part II C program im stuck

 
SOLVED
Go to solution
Mikel Howel_1
Advisor

Part II C program im stuck

ive been working on this and im tryint to pull info from the structure. but its not working i need to add this for each students final grade. the 3 quizes are worth 30% of the grade and the 2 test are worth 70%
something like this

=(quizavg * 0.30)+(testsavg * 0.70)
if(c>=90)

then give it a final grade from the weighted grade. anyhelp with this?

printf("You get an A\n");
else if((c>=80)&&(c<89))
printf("You get a B\n");
else if((c>=70)&&(c<79))
printf("You get a C\n");
else if((c>=60)&&(c<69))
printf("You get a D\n");
else
printf("Failed the class\n");

#include

struct student_info{
char fname[26];
char lname[31];
int quiza[4];
int quizb[4];
int quizc[4];
int testa[4];
int testb[4];

};

typedef struct student_info SI;

int main()
{

SI student[5];
int iJunk;
int iCount;
int quiztot;
int quizavg;
int testtot;
int testavg;

for (iCount = 0; iCount < 3; iCount++){
printf("Students First Name:");
scanf("%s", student[iCount].fname );
iJunk = getchar();


printf("Students Last Name:");
scanf("%s", student[iCount].lname );
iJunk = getchar();

printf("Score for Quiz 1:");
scanf("%d", &student[iCount].quiza );
iJunk = getchar();

printf("Score for Quiz 2:");
scanf("%d", &student[iCount].quizb );
iJunk = getchar();

printf("Score For Quiz 3:");
scanf("%d", &student[iCount].quizc );
iJunk = getchar();

printf("Score For Test 1:");
scanf("%d", &student[iCount].testa );
iJunk = getchar();

printf("Score For Test 2:");
scanf("%d", &student[iCount].testb );
iJunk = getchar();

quiztot = SI.quiza + SI.quizb + SI.quizc;
quizavg = quiztot/3;

testtot = SI.testa + SI.testb;
testavg = testtot/2;

}
printf("\n");

printf("Press a key to continue...\n");
iJunk = getchar();

return 0;
}
26 REPLIES 26
Mikel Howel_1
Advisor

Re: Part II C program im stuck

anyone?
Ron Kinner
Honored Contributor
Solution

Re: Part II C program im stuck

I'll give it a shot since no one else has anything to say.

Seems to me you have defined a datastructure type called SI then made an instance of it called student[].


You then went through a routine which filled student[] with info from keyboard input. I assume this part works OK.

Now you say
"quiztot = SI.quiza + SI.quizb + SI.quizc;
quizavg = quiztot/3; "

But SI is now the type and not the student[] so it is not clear to me what SI.testa refers to. I would think you would need to say:

quiztot = student[iCount].quiza + student[iCount].quizb + student[iCount].quizc

Ron

Rajeev  Shukla
Honored Contributor

Re: Part II C program im stuck

Hi try this one with a structure. You have give First and Second name together and in the end it prints the summary also.

#include
struct data {
char fname[26];
char lname[31];
int quiza, quizb, quizc, testa, testb, grade;
};
main()
{
struct data student[3];
int i, q_total, t_total, q_avg, t_avg;
for (i=0; i<3; i++){
printf("Enter the record No. %d\n", (i+1));
printf("Enter the Students first Name & Second Name: ");
scanf("%s %s", &student[i].fname, &student[i].lname);
printf("Enter the Marks %s %s Got in Quiz A: ", student[i].fname, student[i].lname);
scanf("%d", &student[i].quiza);
printf("Enter the Marks %s %s Got in Quiz B: ", student[i].fname, student[i].lname);
scanf("%d", &student[i].quizb);
printf("Enter the Marks %s %s Got in Quiz C: ", student[i].fname, student[i].lname);
scanf("%d", &student[i].quizc);
printf("Enter the Marks %s %s Got in Test 1: ", student[i].fname, student[i].lname);
scanf("%d", &student[i].testa);
printf("Enter the Marks %s %s Got in Test 2: ", student[i].fname, student[i].lname);
scanf("%d", &student[i].testb);
q_avg = ((student[i].quiza)+(student[i].quizb)+(student[i].quizc))/3;
t_avg = ((student[i].testa)+(student[i].testb))/2;
student[i].grade = (q_avg*0.3)+(t_avg*0.7);
if((student[i].grade)>80)
printf("You have Got Grade A\n");
if((student[i].grade)>60 && (student[i].grade)<80)
printf("You have Got Grade B\n");
if((student[i].grade)>40 && (student[i].grade)<60)
printf("You have Got Grade C\n");
if((student[i].grade)<40)
printf("You Have failed\n");
printf("Average=%d\n", (student[i].grade));

}
puts("");
printf("________________________________________________\n");
for (i=0; i<3; i++)
printf("Entry No: %d, \n\t\t Name: %s %s\n\t\t Grade:%d\n", (i+1), student[i].fname, student[i].lname, student[i].grade);
printf("________________________________________________\n");
}


Let me know if u need more help.

Cheers
Mikel Howel_1
Advisor

Re: Part II C program im stuck

on the printf function on the bottom with the lines, what do they do?

also if i wanted to get a average grade of everyone i entered how do i do that?
Rajeev  Shukla
Honored Contributor

Re: Part II C program im stuck

The last printf function prints each students name and then their final score which is (q_avg*0.3)+(t_avg*0.7).
Just compile and try running it you'll know what is does.

Cheers
Mikel Howel_1
Advisor

Re: Part II C program im stuck

what does the \t mean?

%s %s\n\t\t
Rajeev  Shukla
Honored Contributor

Re: Part II C program im stuck

Hi Mikel,
Thats for a "TAB" singe \t is single TAB. This is used to have a formatted output on the screen.

Cheers
Rajeev
Mikel Howel_1
Advisor

Re: Part II C program im stuck

How do i get a average for all the students averages together to give the class a grade
Rajeev  Shukla
Honored Contributor

Re: Part II C program im stuck

Hi,
The structure element grade has all data for the class so make a loop and add all the elements and divide by number of students which you have defined as 3.
for(i=0;i<3;i++)
sum+=(student[i].grade);
av_class_grade=(sum)/3;

Cheers
Rajeev