Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old May 23rd, 2005, 7:49 PM   #1
takumi8374
Newbie
 
Join Date: May 2005
Posts: 6
Rep Power: 0 takumi8374 is on a distinguished road
Help Plz

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).


#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; May 23rd, 2005 at 8:03 PM.
takumi8374 is offline   Reply With Quote
Old May 26th, 2005, 10:09 PM   #2
Jessehk
The Oblivious One
 
Jessehk's Avatar
 
Join Date: May 2005
Location: Ontario, Canada
Posts: 644
Rep Power: 4 Jessehk is on a distinguished road
I didn't read the code, just what you wanted to do.

declare (A.K.A: create )(if there isn't one already) a variable called int total

then add this line where you want to calculate the total

total = 0.75(quiz1+quiz2+quiz3)+0.25(exam1+exam2+exam3);

display the variable as you wish

eg:

printf(Your Total score is %s.\n", total);

I don't know if that is what you wanted, but I tried.

Last edited by Jessehk; May 26th, 2005 at 10:19 PM.
Jessehk is offline   Reply With Quote
Old May 27th, 2005, 4:49 AM   #3
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
You want a couple of *s in there:
total = 0.75 * (quiz1 + quiz2 + quiz3) + 0.25 * (exam1 + exam2 + exam3);
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Jun 3rd, 2005, 9:04 AM   #4
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Ooble solved your immediate problem. I looked at your code and you are courting plenty more. "Gets" is not a good function to use -- it is susceptible to the dreaded buffer overflow that one hears so much about. Many other mechanisms can be misused, also, but there is just about NO way to do other than misuse "gets". Also, you may not have noticed when you looked up the function, but "scanf" provides a return. To ignore it is to expect the customers, clients, and users to pamper you like yo mama would. Anottagonnahappen in the real world.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Jun 3rd, 2005, 9:14 AM   #5
mitakeet
Programmer
 
mitakeet's Avatar
 
Join Date: Jun 2005
Location: Maryland, USA
Posts: 59
Rep Power: 4 mitakeet is on a distinguished road
Hey DaWei, glad to see you! I guess we need to rebuild our sticky from DevShed, eh?
__________________

Free code: http://sol-biotech.com/code/.

It is not that old programmers are any smarter or code better, it is just that they have made the same stupid mistake so many times that it is second nature to fix it.
--Mitakeet

The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man.
--George Bernard Shaw
mitakeet is offline   Reply With Quote
Old Jun 3rd, 2005, 11:50 AM   #6
Spectre5
Newbie
 
Join Date: Jun 2005
Posts: 8
Rep Power: 0 Spectre5 is on a distinguished road
Ya...nice to see all the DevSheders showing up here
Spectre5 is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 11:29 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC