Grade Evaluator

This is a discussion on Grade Evaluator within the C Programming forums, part of the General Programming Boards category; Hi, I dont really know how to write the function to compute the final score, which is equal to 0.75(quiz1+quiz2+quiz3)+0.25(exam1+exam2+exam3). ...

  1. #1
    Registered User
    Join Date
    May 2005
    Posts
    5

    Grade Evaluator

    Hi, I dont really know how to write the function to compute the final score, which is equal to 0.75(quiz1+quiz2+quiz3)+0.25(exam1+exam2+exam3).


    Code:
    #include<stdio.h>
    
    #define NAME 25
    #define SOCIAL 12
    #define PHONE 15
    #define QUIZ 13
    #define EXAM 13
    #define FINAL 3
    #define SIZE 2
    
    struct {
    	char first[NAME];
    	char last[NAME];
    }typedef Name;
    
    struct {
    	int first3;
    	int middle2;
    	int last4;
    }typedef Social;
    
    struct {
    	int code;
    	int first3;
    	int last4;
    }typedef Phone;
    
    struct {
    	int quiz1[QUIZ];
    	int quiz2[QUIZ];
    	int quiz3[QUIZ];
    }typedef Quiz;
    
    struct {
    	int exam1;
    	int exam2;
    	int exam3;
    }typedef Exam;
    
    struct {
    	Name name;
    	Social social;
    	Phone phone;
    	Quiz quiz;
    	Exam exam;
    } typedef Grade;
    
    void enterGrade(Grade *cptr);
    
    int Final(int quiz int exam);
    
    int main()
    {
    	Grade grade[SIZE];
    	int x;
    	
    	for(x=0;x<SIZE;x++);
    		enterGrade(&grade);
    
    	return 0;
    }
    
    void enterGrade(Grade *cptr)
    {
    	
    	printf("Enter first name: ");
    	gets(cptr->name.first);
    	printf("Enter last name: ");
    	gets(cptr->name.last);
    	printf("Enter social sercurity number: ");
    	scanf("%s", &cptr->social.first3, &cptr->social.middle2,
    		  &cptr->social.last4);
    	printf("Enter phone number: ");
    	scanf("%s", &cptr->phone.code,&cptr->phone.first3,&cptr->phone.last4);
    	printf("Enter 1st quiz score: ");
    	scanf("%d", &cptr->quiz.quiz1);
    	printf("Enter 2nd quiz score: ");
    	scanf("%d", &cptr->quiz.quiz2);
    	printf("Enter 3rd quiz score: ");
    	scanf("%d", &cptr->quiz.quiz3);
    	printf("Enter 1st exam score: ");
    	scanf("%d", &cptr->exam.exam1);
    	printf("Enter 2nd exam score: ");
    	scanf("%d", &cptr->exam.exam2);
    	printf("Enter 3rd exam score: ");
    	scanf("%d", &cptr->exam.exam3);
    
    
    }
    
    int Final (int quiz int exam)
    {
    	Final = 0.75(&cptr->quiz.quiz1+&cptr->quiz.quiz2+&cptr->quiz.quiz3)+
    			0.25(&cptr->exam.exam1+&cptr->exam.exam2+&cptr->exam.exam3);
    	return x;
    }
    Last edited by Takumi8374; 05-23-2005 at 08:03 PM.

  2. #2
    Registered User
    Join Date
    May 2005
    Posts
    5

    revised program

    Code:
    #include<stdio.h>
    
    #define NAME 25
    #define SOCIAL 12
    #define PHONE 15
    #define QUIZ 13
    #define EXAM 13
    #define FINAL 3
    #define SIZE 2
    
    struct {
    	char first[NAME];
    	char last[NAME];
    }typedef Name;
    
    struct {
    	int first3;
    	int middle2;
    	int last4;
    }typedef Social;
    
    struct {
    	int code;
    	int first3;
    	int last4;
    }typedef Phone;
    
    struct {
    	int quiz1[QUIZ];
    	int quiz2[QUIZ];
    	int quiz3[QUIZ];
    }typedef Quiz;
    
    struct {
    	int exam1;
    	int exam2;
    	int exam3;
    }typedef Exam;
    
    struct {
    	Name name;
    	Social social;
    	Phone phone;
    	Quiz quiz;
    	Exam exam;
    } typedef Grade;
    
    void enterGrade(Grade *cptr);
    
    int Final();
    
    int main()
    {
    	Grade grade[SIZE];
    	int x;
    	
    	for(x=0;x<SIZE;x++);
    		enterGrade(&grade[x]);
    
    	return 0;
    }
    
    void enterGrade(Grade *cptr)
    {
    	fflush(stdin);
    	printf("Enter first name: ");
    	gets(cptr->name.first);
    	printf("Enter last name: ");
    	gets(cptr->name.last);
    	fflush(stdin);
    	printf("Enter social sercurity number: ");
    	scanf("%s", &cptr->social.first3, &cptr->social.middle2,
    		  &cptr->social.last4);
    	printf("Enter phone number: ");
    	scanf("%s", &cptr->phone.code,&cptr->phone.first3,&cptr->phone.last4);
    	printf("Enter 1st quiz score: ");
    	scanf("%d", &cptr->quiz.quiz1);
    	printf("Enter 2nd quiz score: ");
    	scanf("%d", &cptr->quiz.quiz2);
    	printf("Enter 3rd quiz score: ");
    	scanf("%d", &cptr->quiz.quiz3);
    	printf("Enter 1st exam score: ");
    	scanf("%d", &cptr->exam.exam1);
    	printf("Enter 2nd exam score: ");
    	scanf("%d", &cptr->exam.exam2);
    	printf("Enter 3rd exam score: ");
    	scanf("%d", &cptr->exam.exam3);
    
    
    }
    
    int Final ()
    {
    	int quiz1,quiz2,quiz3,exam1,exam2,exam3,Final;
    
    	Final = 0.75(quiz1+quiz2+quiz3)+ 0.25(exam1+exam2+exam3);
    	
    	return Final;
    }
    i got 2 errors thats the same and it saids

    error 2064:term does not evaluate to a function taking 26447744.

    can someone please help me and tell me what that means

  3. #3
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    I think you're supposed to put typedef before struct.

    Did the error give a line number or anything?

    Oh yeah, and don't use gets().
    Last edited by dwks; 05-23-2005 at 10:42 PM. Reason: speling

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    Final = 0.75(quiz1+quiz2+quiz3)+ 0.25(exam1+exam2+exam3);
    This is invalid in C. Try this:

    Code:
    Final = 0.75*(quiz1+quiz2+quiz3)+ 0.25*(exam1+exam2+exam3);
    I don't think you ever call Final(). (Was this intentional?)

    Another thing I just noticed is that you have a variable called Final in the function Final(). I don't think this will work.
    Last edited by dwks; 05-24-2005 at 12:05 PM.

  5. #5
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    When you access a member of a pointer to a struct, you don't use an ampersand (&):

    Code:
    int x;
    struct {
        int i;
    } s, *p;
    
    p = &s;
    x = s.i;
    x = p->i;

  6. #6
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,806
    Well, one problem is that your quiz1, quiz2, and quiz3 data members are declared as arrays when it seems (?)they should not be. Haven't looked beyond that, this just jumped out at me.

    Code:
    #define QUIZ 13
    
    struct {
        int quiz1[QUIZ];
        int quiz2[QUIZ];
        int quiz3[QUIZ];
    }typedef Quiz;
    
    struct {
        Name name;
        Social social;
        Phone phone;
        Quiz quiz;
        Exam exam;
    } typedef Grade;
    
    ...
    
    printf("Enter 1st quiz score: ");
    scanf("%d", &cptr->quiz.quiz1);
    printf("Enter 2nd quiz score: ");
    scanf("%d", &cptr->quiz.quiz2);
    printf("Enter 3rd quiz score: ");
    scanf("%d", &cptr->quiz.quiz3);
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can someone help me with these errors please code included
    By geekrockergal in forum C Programming
    Replies: 7
    Last Post: 02-10-2009, 02:20 PM
  2. Compiled without error but Result varies!!
    By RahulDhanpat in forum C Programming
    Replies: 10
    Last Post: 02-12-2008, 10:32 AM
  3. Help me pls...About computing a grade
    By Sunday in forum C Programming
    Replies: 2
    Last Post: 11-03-2007, 01:41 PM
  4. Functions and Structs...
    By pandroff in forum C Programming
    Replies: 1
    Last Post: 12-03-2005, 05:12 PM
  5. Creating a student grade book-how?
    By Hopelessly confused in forum C Programming
    Replies: 5
    Last Post: 10-03-2002, 09:43 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21