![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: May 2005
Posts: 6
Rep Power: 0
![]() |
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. |
|
|
|
|
|
#2 |
|
The Oblivious One
Join Date: May 2005
Location: Ontario, Canada
Posts: 644
Rep Power: 4
![]() |
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. |
|
|
|
|
|
#3 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
You want a couple of *s in there:
total = 0.75 * (quiz1 + quiz2 + quiz3) + 0.25 * (exam1 + exam2 + exam3); |
|
|
|
|
|
#4 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
|
|
#5 |
|
Programmer
Join Date: Jun 2005
Location: Maryland, USA
Posts: 59
Rep Power: 4
![]() |
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 |
|
|
|
|
|
#6 |
|
Newbie
Join Date: Jun 2005
Posts: 8
Rep Power: 0
![]() |
Ya...nice to see all the DevSheders showing up here
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|