If anyone has the time, I am trying to do this program and I can't get it to work. You are supposed to enter test scores into an array according to student ID numbers. When you type "0" for the ID, the list of the array of student id's and their corresponding average is supposed to print out. The array does not display properly. Please Help!
Thankyou
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#define MAX 50
// Function Prototypes
void DisplayGreeting(void);
int GetId(void);
int GetScore(void);
int ComputeExamDifference(int,int);
float ComputeExamAverage(int,int);
float ComputeCourseAverage(int,int,int);
char ComputeGrade(float);
void GenerateCourseReport(int, int, int, int, int, float, float, char);
void Generate_Summary(int [], float [], char [], int);
main()
{
// Data Declarations
int id_student;
int id_array[MAX] = {0}; // Student id
int student_count = 0;
int ex_1; // Exam 1 score
int ex_2; // Exam 2 score
int class_project; // Class project score
int ex_diff; // Difference in score on the 2 exams
float exam_avg; // Exam averages
float course_avg; // Overall class score array
char course_grade; // Letter grade for student array
int score;
float avg_course_array[MAX] = {0};
float grade_course_array[MAX] = {0};
{
DisplayGreeting();
while (1)
{
id_student = GetId();
if (id_student == 0)
break;
id_array[student_count++] = id_student;
printf("\nPlease enter the score for student %i on Exam 1: ", id_student);
ex_1 = GetScore();
printf("\nPlease enter the score for student %i on Exam 2: ", id_student);
ex_2 = GetScore();
printf("\nPlease enter the score for student %i on Class Project: ", id_student);
class_project = GetScore();
printf("\nPress any key to continue"
getch();
ex_diff = ComputeExamDifference(ex_1, ex_2);
exam_avg = ComputeExamAverage(ex_1, ex_2);
course_avg = ComputeCourseAverage(ex_1, ex_2, class_project);
avg_course_array[student_count] = course_avg;
course_grade = ComputeGrade(course_avg);
grade_course_array[student_count] = course_grade;
GenerateCourseReport(id_student, ex_1, ex_2, class_project, ex_diff, exam_avg, course_avg, course_grade);
}
Generate_Summary(id_array, avg_course_array, grade_course_array, student_count);
}
return 0;
}
// Functions
void DisplayGreeting(void) // Displays the greeting
{
system("cls"
printf("\n**************************************"
printf("\n* *"
printf("\n* Welcome to the UCD ISMG 2200 *"
printf("\n* On-line Information System *"
printf("\n* *"
printf("\n**************************************"
return;
}
int GetId(void) // Gets the student id number
{
int id_student;
{
printf("\n\nPlease enter the student ID number: "
scanf("%i", &id_student);
fflush(stdin);
if (id_student >= 0 && id_student <= 999999999)
return id_student;
else
printf("\n*** Error! Student ID of %i is out of range! ***", id_student);
GetId();
}
}
int GetScore(void) // Gets the score for the student
{
int score;
do
{
scanf("%i", &score);
if(score <=100 && score >= 0)
break;
printf("\n***Score of %i is out of range! Please try again ***\n", score);
}
while(1);
return score;
}
int ComputeExamDifference(int ex_1, int ex_2) // Calculates the difference between exam 1 and 2
{
int ex_diff;
ex_diff = ex_2 - ex_1;
return ex_diff;
}
float ComputeExamAverage(int ex_1, int ex_2) // Averages the exam averages
{
float exam_avg;
exam_avg = (float) (ex_1 + ex_2) / 2;
return exam_avg;
}
float ComputeCourseAverage(int ex_1, int ex_2, int class_project) // Averages the course average
{
const float weight_ex1 = .35; // Exam 1 score weighted
const float weight_ex2 = .25; // Exam 2 score weighted
const float weight_project = .40; // Class project score weighted
float course_avg;
{
course_avg = ((float)weight_ex1*ex_1) + ((float)weight_ex2*ex_2) + ((float)weight_project*class_project);
return course_avg;
}
}
char ComputeGrade(float course_avg) // Assigns a grade to the student
{
char course_grade;
{
if (course_avg >= 90)
{
course_grade = 'A';
return course_grade;
}
else if (course_avg >= 80)
{
course_grade = 'B';
return course_grade;
}
else if (course_avg >= 70)
{
course_grade = 'C';
return course_grade;
}
else if (course_avg >= 60)
{
course_grade = 'D';
return course_grade;
}
else
{
course_grade = 'F';
return course_grade;
}
}
}
// Output
void GenerateCourseReport(int id, int ex_1, int ex_2, int class_project, int ex_diff, float exam_avg, float course_avg, char course_grade) //Displays the output
{
system("cls"
printf("\n **** Course Report for Student %i ****", id);
printf("\n\nStudent scored %i on Exam 1", ex_1);
printf("\nStudent scored %i on Exam 2", ex_2);
printf("\nStudent scored %i on Class Project", class_project);
printf("\n\nStudent scored %i points differently on Exam 2 versus Exam 1", ex_diff);
printf("\n\nStudent's exam average is %3.2f", exam_avg);
printf("\n\nStudent's average for the course is %3.2f\n", course_avg);
printf("\nStudent's grade in course is %c\n", course_grade);
printf("\nPress any key to continue"
getch();
system("cls"
return;
}
void Generate_Summary(int student_count, int id_array, float avg_course_array, char grade_course_array)
{
printf("\n *** ISMG 2200 Summary Course Report ***"
printf("\n Student ID Average Grade"
printf("\n ---------- ------- -----"
for (student_count = 0; student_count <= MAX; student_count++)
printf("\n %i %i %3.2f %c", student_count, id_array, avg_course_array, grade_course_array);
return;
}
Thankyou
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#define MAX 50
// Function Prototypes
void DisplayGreeting(void);
int GetId(void);
int GetScore(void);
int ComputeExamDifference(int,int);
float ComputeExamAverage(int,int);
float ComputeCourseAverage(int,int,int);
char ComputeGrade(float);
void GenerateCourseReport(int, int, int, int, int, float, float, char);
void Generate_Summary(int [], float [], char [], int);
main()
{
// Data Declarations
int id_student;
int id_array[MAX] = {0}; // Student id
int student_count = 0;
int ex_1; // Exam 1 score
int ex_2; // Exam 2 score
int class_project; // Class project score
int ex_diff; // Difference in score on the 2 exams
float exam_avg; // Exam averages
float course_avg; // Overall class score array
char course_grade; // Letter grade for student array
int score;
float avg_course_array[MAX] = {0};
float grade_course_array[MAX] = {0};
{
DisplayGreeting();
while (1)
{
id_student = GetId();
if (id_student == 0)
break;
id_array[student_count++] = id_student;
printf("\nPlease enter the score for student %i on Exam 1: ", id_student);
ex_1 = GetScore();
printf("\nPlease enter the score for student %i on Exam 2: ", id_student);
ex_2 = GetScore();
printf("\nPlease enter the score for student %i on Class Project: ", id_student);
class_project = GetScore();
printf("\nPress any key to continue"
getch();
ex_diff = ComputeExamDifference(ex_1, ex_2);
exam_avg = ComputeExamAverage(ex_1, ex_2);
course_avg = ComputeCourseAverage(ex_1, ex_2, class_project);
avg_course_array[student_count] = course_avg;
course_grade = ComputeGrade(course_avg);
grade_course_array[student_count] = course_grade;
GenerateCourseReport(id_student, ex_1, ex_2, class_project, ex_diff, exam_avg, course_avg, course_grade);
}
Generate_Summary(id_array, avg_course_array, grade_course_array, student_count);
}
return 0;
}
// Functions
void DisplayGreeting(void) // Displays the greeting
{
system("cls"
printf("\n**************************************"
printf("\n* *"
printf("\n* Welcome to the UCD ISMG 2200 *"
printf("\n* On-line Information System *"
printf("\n* *"
printf("\n**************************************"
return;
}
int GetId(void) // Gets the student id number
{
int id_student;
{
printf("\n\nPlease enter the student ID number: "
scanf("%i", &id_student);
fflush(stdin);
if (id_student >= 0 && id_student <= 999999999)
return id_student;
else
printf("\n*** Error! Student ID of %i is out of range! ***", id_student);
GetId();
}
}
int GetScore(void) // Gets the score for the student
{
int score;
do
{
scanf("%i", &score);
if(score <=100 && score >= 0)
break;
printf("\n***Score of %i is out of range! Please try again ***\n", score);
}
while(1);
return score;
}
int ComputeExamDifference(int ex_1, int ex_2) // Calculates the difference between exam 1 and 2
{
int ex_diff;
ex_diff = ex_2 - ex_1;
return ex_diff;
}
float ComputeExamAverage(int ex_1, int ex_2) // Averages the exam averages
{
float exam_avg;
exam_avg = (float) (ex_1 + ex_2) / 2;
return exam_avg;
}
float ComputeCourseAverage(int ex_1, int ex_2, int class_project) // Averages the course average
{
const float weight_ex1 = .35; // Exam 1 score weighted
const float weight_ex2 = .25; // Exam 2 score weighted
const float weight_project = .40; // Class project score weighted
float course_avg;
{
course_avg = ((float)weight_ex1*ex_1) + ((float)weight_ex2*ex_2) + ((float)weight_project*class_project);
return course_avg;
}
}
char ComputeGrade(float course_avg) // Assigns a grade to the student
{
char course_grade;
{
if (course_avg >= 90)
{
course_grade = 'A';
return course_grade;
}
else if (course_avg >= 80)
{
course_grade = 'B';
return course_grade;
}
else if (course_avg >= 70)
{
course_grade = 'C';
return course_grade;
}
else if (course_avg >= 60)
{
course_grade = 'D';
return course_grade;
}
else
{
course_grade = 'F';
return course_grade;
}
}
}
// Output
void GenerateCourseReport(int id, int ex_1, int ex_2, int class_project, int ex_diff, float exam_avg, float course_avg, char course_grade) //Displays the output
{
system("cls"
printf("\n **** Course Report for Student %i ****", id);
printf("\n\nStudent scored %i on Exam 1", ex_1);
printf("\nStudent scored %i on Exam 2", ex_2);
printf("\nStudent scored %i on Class Project", class_project);
printf("\n\nStudent scored %i points differently on Exam 2 versus Exam 1", ex_diff);
printf("\n\nStudent's exam average is %3.2f", exam_avg);
printf("\n\nStudent's average for the course is %3.2f\n", course_avg);
printf("\nStudent's grade in course is %c\n", course_grade);
printf("\nPress any key to continue"
getch();
system("cls"
return;
}
void Generate_Summary(int student_count, int id_array, float avg_course_array, char grade_course_array)
{
printf("\n *** ISMG 2200 Summary Course Report ***"
printf("\n Student ID Average Grade"
printf("\n ---------- ------- -----"
for (student_count = 0; student_count <= MAX; student_count++)
printf("\n %i %i %3.2f %c", student_count, id_array, avg_course_array, grade_course_array);
return;
}