1753909 Members
8971 Online
108810 Solutions
New Discussion юеВ

Re: C Program, im stuck

 
SOLVED
Go to solution
Mikel Howel
Occasional Advisor

C Program, im stuck

im doing a Grading program but i cant get the quiz scores to average, and the test to average as well. can anyone help me, its a C program
i think i can make a temp variable, but how?

#include

int main(int argc,char*argv[])




{
int ch;
int c;
int iJunk;

c = 0;

ch = ' ';


printf("\nEnter Grade For Quiz 1:\n");
scanf("%d",&c);
ch = getc(stdin);

printf("\nEnter Grade For Quiz 2:\n");
scanf("%d",&c);
ch = getc(stdin);

printf("\nEnter Grade For Quiz 3:\n");
scanf("%d",&c);
ch = getc(stdin);

printf("\nEnter Grade For Test 1:\n");
scanf("%d",&c);
ch = getc(stdin);

printf("\nEnter Grade For Test 2:\n");
scanf("%d",&c);
ch = getc(stdin);


if(c>=90)
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");

ch = getc(stdin);



return 0;


}
18 REPLIES 18
harry d brown jr
Honored Contributor
Solution

Re: C Program, im stuck


Where are you magically adding up scores, counting the number of "scores", and doing division?

live free or die
harry
Live Free or Die
Mikel Howel
Occasional Advisor

Re: C Program, im stuck

Thats what im having trouble with, i dont know how to make it so it will add up the scores for the quiz, and the test sepertly. it only gives a grade for the last data entry. this is as far as i could go, but im stuck the rest of the way...
harry d brown jr
Honored Contributor

Re: C Program, im stuck


Use an array for the scores or

declare another int

int tot;

then after each getc(stdin) line do this:

tot += c;

then before the IF tests do this:

c = tot / 5;


live free or die
harry
Live Free or Die
Mikel Howel
Occasional Advisor

Re: C Program, im stuck

like this? i feel like a dummy asking all these questions. if this is not right could you copy and paste and insert? ive been working on this all day and im getting frustrated. thanks

#include

int main(int argc,char*argv[])




{
int ch;
int c;
int iJunk;
int tot;

c = 0;

ch = ' ';


printf("\nEnter Grade For Quiz 1:\n");
scanf("%d",&c);
ch = getc(stdin);
tot += c;

printf("\nEnter Grade For Quiz 2:\n");
scanf("%d",&c);
ch = getc(stdin);
tot += c;

printf("\nEnter Grade For Quiz 3:\n");
scanf("%d",&c);
ch = getc(stdin);
tot += c;

printf("\nEnter Grade For Test 1:\n");
scanf("%d",&c);
ch = getc(stdin);
tot += c;

printf("\nEnter Grade For Test 2:\n");
scanf("%d",&c);
ch = getc(stdin);
tot += c;

c = tot / 5;
if(c>=90)
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");

ch = getc(stdin);



return 0;


}
Rajeev  Shukla
Honored Contributor

Re: C Program, im stuck

Hi Try out this simple one where you pass the number of quize as argument and then supply the marks for each quiz and finally it prints the Grade and the average.
Let me know if you need more help in modifying it.

#include
#include
#define MAX 10
main(argc,argv)
int argc;
char *argv[];
{
int i,j, buff[MAX], k, avr;
k=0;
if(argc != 2){
printf("Usage: %s \n", argv[0]);
exit(1);
}
i = atof(argv[1]);
for(j=0;j printf("Enter the Marks for Quiz %d:", (j+1));
scanf("%d", &buff[j]);
}
for(j=0;j k=k+buff[j];
avr = k/i;
if(avr>80)
printf("You have Got Grade A\n");
if((avr>60) && (avr<80))
printf("You have Got Grade B\n");
if((avr>40) && (avr<60))
printf("You have Got Grade C\n");
if(avr<40)
printf("You Have failed\n");
printf("Average=%d\n", avr);
}

Cheers
Rajeev
Mikel Howel
Occasional Advisor

Re: C Program, im stuck

I can see what your geting at, but when i run it, it says you have 33 errors.
Mikel Howel
Occasional Advisor

Re: C Program, im stuck

But that is what i want to do, enter number of quizes, and also do same for test. get a average for quiz, and average for test. then get a group average of everyone i entered. this is whatis throwing me for a loop
Yogeeraj_1
Honored Contributor

Re: C Program, im stuck

hi,
the code posted by Rajeev works fine!

Did you compile the program?
==============================
L1000: home/yogeeraj>cc test2.c
/usr/ccs/bin/ld: (Warning) At least one PA 2.0 object file (test2.o) was detected. The linked output may not run on a PA 1.x system.
L1000: home/deg>a.out
Usage: a.out
L1000: home/yogeeraj>a.out 11
Enter the Marks for Quiz 1:12
Enter the Marks for Quiz 2:12
Enter the Marks for Quiz 3:34
Enter the Marks for Quiz 4:45
Enter the Marks for Quiz 5:67
Enter the Marks for Quiz 6:34
Enter the Marks for Quiz 7:67
Enter the Marks for Quiz 8:34
Enter the Marks for Quiz 9:67
Enter the Marks for Quiz 10:345
Enter the Marks for Quiz 11:345
You have Got Grade A
Average=193
L1000: home/yogeeraj>
==============================

Why don't describe your problem with an example?

regards
Yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
Yogeeraj_1
Honored Contributor

Re: C Program, im stuck

hi,
the code posted by Rajeev works fine!

Did you compile the program?
==============================
L1000: home/yogeeraj>cc test2.c
/usr/ccs/bin/ld: (Warning) At least one PA 2.0 object file (test2.o) was detected. The linked output may not run on a PA 1.x system.
L1000: home/deg>a.out
Usage: a.out
L1000: home/yogeeraj>a.out 11
Enter the Marks for Quiz 1:12
Enter the Marks for Quiz 2:12
Enter the Marks for Quiz 3:34
Enter the Marks for Quiz 4:45
Enter the Marks for Quiz 5:67
Enter the Marks for Quiz 6:34
Enter the Marks for Quiz 7:67
Enter the Marks for Quiz 8:34
Enter the Marks for Quiz 9:67
Enter the Marks for Quiz 10:345
Enter the Marks for Quiz 11:345
You have Got Grade A
Average=193
L1000: home/yogeeraj>
==============================

Why don't describe your problem with an example?

regards
Yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)