- Joined
- Jul 23, 2008
- Messages
- 691
- Reaction score
- 90
Hey, so I'm doing a program in C where basically I have to compute grades of students. The user will send to me the name, their answerkey(since the test is a 20 question true/false format), and then repeat this for 3 more students. Once they have done so, I'm to print their results and the student who got the highest grade amongst the 4.
Here's my code so far:
The code is a bit incomplete, its just that I feel i'm so fundamentally wrong that I'd like someone who's experienced to fill me in here.
Thanks alot.
Here's my code so far:
Code:
#include <stdio.h>
struct stud{
int students[5];
char name[20];
int answerkey[20];
char grade[5];
int correct;
};
void Init();
void readData();
int findGrade();
void printAll();
char grade;
void main() {
int grade;
readData(&s1, &s2, &s3, &s4);
}
void Init () {
int i = 0;
int j = 0;
}
void readData(struct stud *students) {
int correctkey[20];
int i = 0;
for (i = 0; i < 5; ++i) {
printf("Please enter the students name \n");
scanf("%s", students[i].name);
printf("Please enter their respective answers \n");
scanf("&d", students[i].answerkey);
i++;
}
int findGrade(int *answerkey, int *correctkey, struct stud *students) {
int correct = 0;
int j = 0;
int scorekey, scorehigh;
for (j = 0; j < 20; j++) {
if (answerkey[j] == correctkey[j])
correct++;
}
if (correct <= 20) {
grade = "A";
}
else if (correct <= 16) {
grade = "B";
}
else if (correct <= 14){
grade = "C";
}
else if (correct <= 12){
grade = "D";
}
else if (correct <= 11){
grade = "F";
}
/* if (students.correct[0] > students.correct[1] && students.correct[2] && students.correct[3]) {
highest = students[0].correct;
scorekey = students[0].answerkey
else if (students.correct[1] > students.correct[0] && students.correct[2] && students.correct[3])
highest = students[1].correct;
scorekey = students[1].answerkey
else if (students.correct[2] > students.correct[0] && students.correct[1] && students.correct[3])
highest = students[2].correct;
scorekey = students[2].answerkey
else if (students.correct[3] > students.correct[2] && students.correct[1] && students.correct[0])
highest = students[3].correct;
scorekey = students[3].answerkey
*/
}
void printAll () {
printf("Name\tStudent Answers\t\t\tAnswers-Correct\tGrade");
printf("%s\t%d\t%d\t%s", student.name, student.answerkey, student.correct, student.grade);
printf("%s\t%d\t%d\t%s", student.name, student.answerkey, student.correct, student.grade);
printf("%s\t%d\t%d\t%s", student.name, student.answerkey, student.correct, student.grade);
printf("%s\t%d\t%d\t%s", student.name, student.answerkey, student.correct, student.grade);
printf("answerkey \t\t Highest Score");
printf("%d \t %d", scorekey, highest);
}
The code is a bit incomplete, its just that I feel i'm so fundamentally wrong that I'd like someone who's experienced to fill me in here.
Thanks alot.