Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Just beginning- NEED HELP!

Status
Not open for further replies.

coors

MIS
Aug 14, 2002
1
CA
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(&quot;\nPlease enter the score for student %i on Exam 1: &quot;, id_student);
ex_1 = GetScore();
printf(&quot;\nPlease enter the score for student %i on Exam 2: &quot;, id_student);
ex_2 = GetScore();
printf(&quot;\nPlease enter the score for student %i on Class Project: &quot;, id_student);
class_project = GetScore();
printf(&quot;\nPress any key to continue&quot;);
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(&quot;cls&quot;);
printf(&quot;\n**************************************&quot;);
printf(&quot;\n* *&quot;);
printf(&quot;\n* Welcome to the UCD ISMG 2200 *&quot;);
printf(&quot;\n* On-line Information System *&quot;);
printf(&quot;\n* *&quot;);
printf(&quot;\n**************************************&quot;);
return;
}

int GetId(void) // Gets the student id number
{
int id_student;
{
printf(&quot;\n\nPlease enter the student ID number: &quot;);
scanf(&quot;%i&quot;, &id_student);
fflush(stdin);
if (id_student >= 0 && id_student <= 999999999)
return id_student;
else
printf(&quot;\n*** Error! Student ID of %i is out of range! ***&quot;, id_student);
GetId();
}
}

int GetScore(void) // Gets the score for the student
{
int score;
do
{
scanf(&quot;%i&quot;, &score);
if(score <=100 && score >= 0)
break;
printf(&quot;\n***Score of %i is out of range! Please try again ***\n&quot;, 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(&quot;cls&quot;);
printf(&quot;\n **** Course Report for Student %i ****&quot;, id);
printf(&quot;\n\nStudent scored %i on Exam 1&quot;, ex_1);
printf(&quot;\nStudent scored %i on Exam 2&quot;, ex_2);
printf(&quot;\nStudent scored %i on Class Project&quot;, class_project);
printf(&quot;\n\nStudent scored %i points differently on Exam 2 versus Exam 1&quot;, ex_diff);
printf(&quot;\n\nStudent's exam average is %3.2f&quot;, exam_avg);
printf(&quot;\n\nStudent's average for the course is %3.2f\n&quot;, course_avg);
printf(&quot;\nStudent's grade in course is %c\n&quot;, course_grade);
printf(&quot;\nPress any key to continue&quot;);
getch();
system(&quot;cls&quot;);

return;
}

void Generate_Summary(int student_count, int id_array, float avg_course_array, char grade_course_array)
{
printf(&quot;\n *** ISMG 2200 Summary Course Report ***&quot;);
printf(&quot;\n Student ID Average Grade&quot;);
printf(&quot;\n ---------- ------- -----&quot;);
for (student_count = 0; student_count <= MAX; student_count++)
printf(&quot;\n %i %i %3.2f %c&quot;, student_count, id_array, avg_course_array, grade_course_array);
return;
}
 
watch the parameter-lists in your function-declaration as well as in the functions definition.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top