Hi. Im new to programming and to this website and i need help with one of my assignments. The instructions for the assignment are to "write a program that uses an array of student structures to answer inquiries. Using a menu-driven user interface, provide inquiries that report a student's score, average, or grade. A fourth menu option provides all data for a requested student, and a fifth prints a list of student IDs and names". My code runs but when it does, i keep getting an error and i definitely dont know what's wrong with it. Please any help will be appreciated. oh and sorry that my code is so long...that's the only way that i know how to do it. Thanks.
Here's my code:
/* Janice Flores
COP 2220 - Online
Summer 2008
Prof. Enger
Ch 12 - Project 40
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
// Global Declarations
typedef struct
{
int id[5];
char name[5];
int quiz1[5];
int quiz2[5];
int quiz3[5];
int quiz4[5];
int exam[5];
} STUDENT;
void menu(int option);
void studentAverage(double average);
char scoreToGrade (int score);
int studentid;
int main (void)
{
// Local Declarations
STUDENT student;
int option, average, score;
menu(option);
// Statements
student.id[0] = 1234;
student.id[1] = 2134;
student.id[2] = 3124;
student.id[3] = 4532;
student.id[4] = 4678;
student.name[0] = "Julie Adams";
student.name[1] = "Harry Smith";
student.name[2] = "Tuan Nguyen";
student.name[3] = "Jorge Gonzalez";
student.name[4] = "Amanda Trapp";
student.quiz1[0] = 52;
student.quiz1[1] = 90;
student.quiz1[2] = 100;
student.quiz1[3] = 11;
student.quiz1[4] = 20;
student.quiz2[0] = 7;
student.quiz2[1] = 36;
student.quiz2[2] = 45;
student.quiz2[3] = 17;
student.quiz2[4] = 12;
student.quiz3[0] =100;
student.quiz3[1] = 90;
student.quiz3[2] = 20;
student.quiz3[3] = 81;
student.quiz3[4] = 45;
student.quiz4[0] = 78;
student.quiz4[1] = 77;
student.quiz4[2] = 90;
student.quiz4[3] = 32;
student.quiz4[4] = 78;
student.exam[0] = 34;
student.exam[1] = 30;
student.exam[2] = 70;
student.exam[3] = 77;
student.exam[4] = 34;
if (option = 1)
{
printf("\n\nEnter Student ID: ");
scanf("%d", studentid);
printf("Student's Name Quiz 1 Quiz 2 Quiz 3 Quiz 4 Exam\n");
printf("============== ====== ====== ====== ====== ====\n\n");
if (studentid = student.id[0])
{
printf("%-26c %4d %4d %4d %4d %4d\n",
student.name[0],
student.quiz1[0],
student.quiz2[0],
student.quiz3[0],
student.quiz4[0],
student.exam[0]);
studentAverage(average);
scoreToGrade(score);
}
else if (studentid = student.id[1])
{
printf("%-26c %4d %4d %4d %4d %4d\n",
student.name[1],
student.quiz1[1],
student.quiz2[1],
student.quiz3[1],
student.quiz4[1],
student.exam[1]);
studentAverage(average);
scoreToGrade(score);
}
else if (studentid = student.id[2])
{
printf("%-26c %4d %4d %4d %4d %4d\n",
student.name[2],
student.quiz1[2],
student.quiz2[2],
student.quiz3[2],
student.quiz4[2],
student.exam[2]);
studentAverage(average);
scoreToGrade(score);
}
else if (studentid = student.id[3])
{
printf("%-26c %4d %4d %4d %4d %4d\n",
student.name[3],
student.quiz1[3],
student.quiz2[3],
student.quiz3[3],
student.quiz4[3],
student.exam[3]);
studentAverage(average);
scoreToGrade(score);
}
else if (studentid = student.id[4])
{
printf("%-26c %4d %4d %4d %4d %4d\n",
student.name[4],
student.quiz1[4],
student.quiz2[4],
student.quiz3[4],
student.quiz4[4],
student.exam[4]);
studentAverage(average);
scoreToGrade(score);
}
else if (studentid = student.id[5])
{
printf("%-26c %4d %4d %4d %4d %4d\n",
student.name[5],
student.quiz1[5],
student.quiz2[5],
student.quiz3[5],
student.quiz4[5],
student.exam[5]);
studentAverage(average);
scoreToGrade(score);
}
}
else if (option = 2)
{
printf("\n\nEnter Student ID: ");
scanf("%d", studentid);
studentAverage(average);
}
else if (option = 3)
{
printf("\n\nEnter Student ID: ");
scanf("%d", studentid);
scoreToGrade(score);
}
else if (option = 4)
{
printf("\n\nEnter Student ID: ");
scanf("%d", studentid);
printf("Student's Name Quiz 1 Quiz 2 Quiz 3 Quiz 4 Exam\n");
printf("============== ====== ====== ====== ====== ====\n\n");
if (studentid = student.id[0])
{
printf("%-26c %4d %4d %4d %4d %4d\n",
student.name[0],
student.quiz1[0],
student.quiz2[0],
student.quiz3[0],
student.quiz4[0],
student.exam[0]);
studentAverage(average);
scoreToGrade(score);
}
else if (studentid = student.id[1])
{
printf("%-26c %4d %4d %4d %4d %4d\n",
student.name[1],
student.quiz1[1],
student.quiz2[1],
student.quiz3[1],
student.quiz4[1],
student.exam[1]);
studentAverage(average);
scoreToGrade(score);
}
else if (studentid = student.id[2])
{
printf("%-26c %4d %4d %4d %4d %4d\n",
student.name[2],
student.quiz1[2],
student.quiz2[2],
student.quiz3[2],
student.quiz4[2],
student.exam[2]);
studentAverage(average);
scoreToGrade(score);
}
else if (studentid = student.id[3])
{
printf("%-26c %4d %4d %4d %4d %4d\n",
student.name[3],
student.quiz1[3],
student.quiz2[3],
student.quiz3[3],
student.quiz4[3],
student.exam[3]);
studentAverage(average);
scoreToGrade(score);
}
else if (studentid = student.id[4])
{
printf("%-26c %4d %4d %4d %4d %4d\n",
student.name[4],
student.quiz1[4],
student.quiz2[4],
student.quiz3[4],
student.quiz4[4],
student.exam[4]);
studentAverage(average);
scoreToGrade(score);
}
else if (studentid = student.id[5])
{
printf("%-26c %4d %4d %4d %4d %4d\n",
student.name[5],
student.quiz1[5],
student.quiz2[5],
student.quiz3[5],
student.quiz4[5],
student.exam[5]);
studentAverage(average);
scoreToGrade(score);
}
}
else
printf("%d\n", student.id[5]);
printf("%c\n", student.name[5]);
system("pause");
return 0;
} // main
void menu(int option)
{
printf("\t*MENU*\t\n\n");
printf("1. View Student's Score\n");
printf("2. View Student's Average\n");
printf("3. View Student's Grade\n");
printf("4. View Complete Student's Data\n");
printf("5. View All Student IDs and Names\n\n");
printf("Choose Option: ");
scanf("%d", option);
}
void studentAverage(double average)
{
if (studentid = 1234)
average = 54;
else if (studentid = 2134)
average = 65;
else if (studentid = 3124)
average = 51;
else if (studentid = 4532)
average = 44;
else if (studentid = 5678)
average = 38;
printf("The student's average is: %.2f", average);
}
char scoreToGrade (int score)
{
char grade;
double average;
average = score;
if (studentid = 1234)
average = 54;
else if (studentid = 2134)
average = 65;
else if (studentid = 3124)
average = 51;
else if (studentid = 4532)
average = 44;
else if (studentid = 5678)
average = 38;
if (score >= 90)
grade = 'A';
else if (score >= 80)
grade = 'B';
else if (score >= 70)
grade = 'C';
else if (score >= 60)
grade = 'D';
else
grade = 'F';
printf("The grade is: %c\n", grade);
} // scoreToGrade