Operating System - HP-UX
1752679 Members
5661 Online
108789 Solutions
New Discussion юеВ

Re: Part II C program im stuck

 
SOLVED
Go to solution
Mikel Howel_1
Advisor

Re: Part II C program im stuck

could i just plug that code in and it would work? where would be the best place to put it?
Mikel Howel_1
Advisor

Re: Part II C program im stuck

is this how i would get the average for the class? i tried it and it didnt work, i declared the variable. help?

for(iCount=0;iCount<3;iCount++)
sum+=(student[iCount].grade);
av_class_grade=(sum)/3;

if((av_class_grade)>90)//Gives letter grade
printf("They have a A\n", student[iCount].fname, student[iCount].lname);

else if((av_class_grade=(sum))>80 && (av_class_grade=(sum))<= 90)
printf("They have a B\n");

else if((av_class_grade=(sum))>70 && (av_class_grade=(sum))<= 80)
printf("They have a C\n");

else if((av_class_grade=(sum))>60 && (av_class_grade=(sum))<= 70)
printf("They have a D\n");

else if((av_class_grade=(sum))<60)
printf("They failed the class\n");
}
Mikel Howel_1
Advisor

Re: Part II C program im stuck

also i think i did the grades wrong because if they get a 89 79 69 they fail,i tried to make it equal or greater than but it still didnt work.
Rajeev  Shukla
Honored Contributor

Re: Part II C program im stuck

As per the code i gave before you need to define
int sum, av_class_grade;
after #include
and then just at the end add the following code
sum=0;
for(i=0;i<3;i++)
sum+=(student[i].grade);
av_class_grade=(sum)/3;
printf("%d %d\n", av_class_grade, sum);
if(av_class_grade>80)
printf("The Class has Got Grade A\n");
if(av_class_grade>60 && av_class_grade<80)
printf("The Class has Got Grade B\n");
if(av_class_grade>40 && av_class_grade<60)
printf("The Class has Got Grade C\n");
if(av_class_grade<40)
printf("The Class has failed\n");


it should work.

Cheers
Rajeev
Mikel Howel_1
Advisor

Re: Part II C program im stuck

im implementing that into theprogram right now, so i just put it after the student grades correct? and if i wanted it to only print the class average at the end of the program it could do that right? also, Im also thinking that if i made the program so you could enter x amount of people. and have a question asking if you want to continue y/n. then if you said n, it would print of all the class results, but if you push yes you could keep entering students.

could i just make a variable for the students so ican add more than 3?
Rajeev  Shukla
Honored Contributor

Re: Part II C program im stuck

Yes you could ask more students than 3 by asking for argument in the program. Change the main program to look something like this.
main(argc, argv)
int argc;
char *argv[];
{
if (argc != 2){
printf("Usage: %s \n", argv[0]);
exit(1);
}
Then continue with the normal codes...

cheers
Rajeev
Mikel Howel_1
Advisor

Re: Part II C program im stuck

if i did that then it would let me enter x number of people right?

im having problems with it printing to the final output. it gives some funky numbers.
Rajeev  Shukla
Honored Contributor

Re: Part II C program im stuck

Yes it would let you x number of people but what you need to do is convert this character to intiger by atoi function. So the number of students will actually be .
no of student say x=atoi(argv[1]);

and then u'll have to change the student count from 3 to the x variable where ever you are doing for(i=0;i<3...make x

The program should be fine after that.

Cheers
Rajeev
Mikel Howel_1
Advisor

Re: Part II C program im stuck

 
Rajeev  Shukla
Honored Contributor

Re: Part II C program im stuck

Here is the full code.
#include
int sum, av_class_grade;
struct data {
char fname[26];
char lname[31];
int quiza, quizb, quizc, testa, testb, grade;
};
main(argc, argv)
int argc;
char *argv[];
{
struct data student[3];
int i, q_total, t_total, q_avg, t_avg;
int x;
if(argc != 2){
printf("Usage: %s \n", argv[0]);
exit(1);
}
x=atoi(argv[1]);
for (i=0; 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 printf("Entry No: %d, \n\t\t Name: %s %s\n\t\t Average Grade:%d\n", (i+1), student[i].fname, student[i].lname, student[i].grade);
printf("________________________________________________\n");
sum=0;
for(i=0;isum+=(student[i].grade);
av_class_grade=(sum)/3;
if(av_class_grade>80)
printf("The Class has Got Grade A\n");
if(av_class_grade>60 && av_class_grade<80)
printf("The Class has Got Grade B\n");
if(av_class_grade>40 && av_class_grade<60)
printf("The Class has Got Grade C\n");
if(av_class_grade<40)
printf("The Class has failed\n");
}

Just copy and run this with number of students as argument.

Cheers
Rajeev