Hello guys. I'm currently having problems concerning displaying a student with the highest grade. I tried to start the calculation under totals but I'm currently having a hard time with it. May someone please point me in the right direction.
/*+*+*+*+*+*+*+* Preprocessor Directives *+*+*+*+*+*+*+*/
#include <stdio.h>
#include <string.h>
#include <iostream>
/*+*+*+*+*+*+*+* Function Prototypes *+*+*+*+*+*+*+*/
void WelcomeInfo (void); /* Welcomes the user */
void AskQuestion(void); /* Asks the user a question */
void GetClass(void); /* Gets the input */
void GetStudentGrade(void);
void NameofStudent(void);
void PerformCalc(void); /* Performs the calculation */
void GradeDisplay(void);
void Totals(void);
void WeightedGrade(void);
void AskQuestion2(void); /* Asks the user a question */
void PrintAStarLine(void);
void TotalPageDisplay(void);
/*+*+*+*+*+*+*+* Variables *+*+*+*+*+*+*+*/
void Font( const char *Input, char *Output )
{
int Length, Size;
Length = strlen( Input );
for( Size=0; Size<Length; Size++ )
{
if( Input[Size]>='a' && Input[Size]<='z' )
Output[Size]=Input[Size]-32;
else
Output[Size]=Input[Size];
}
Output[Size]=0x00;
}
float test1;
float test2;
float project1;
float project2;
float midterm;
float final;
float tests;
float projects;
float midtermexam;
float finalexam;
float studentgrade;
int bonus = 0;
float totalaverage;
int totalstudents;
int studentA = 0;
int studentB = 0;
int studentC = 0;
int studentD = 0;
int studentF = 0;
char newline;
char courseNumber[10];
char cName;
char cMore;
char Name[30];
char StudentName[30];
char StudentfirstName[15];
char StudentlastName[15];
char studentandgrade;
char HighestAverage;
char K;
/*+*+*+*+*+*+*+*^ The Main Module ^*+*+*+*+*+*+*+*/
main()
{
cName = 'N';
do
{
WelcomeInfo();
AskQuestion();
} while ((cName != 'Y') && (cName != 'y'));
cMore = 'Y';
do
{
GetClass();
NameofStudent();
system("cls");
GetStudentGrade();
system("cls");
PerformCalc();
WeightedGrade();
system("cls");
GradeDisplay();
AskQuestion2();
Totals();
}while ((cMore != 'N') && (cMore != 'n')); /* It will loop until user enter N */
TotalPageDisplay();
return 0;
}
/*------------------------------------------------------------
Welcomes the user
------------------------------------------------------------*/
void WelcomeInfo (void)
{
printf("Enter your name please. ");
scanf( "%[^\n]%c", Name, &newline );
printf("\n\n\n");
printf("\t\t\t\t Welcome %s", Name);
printf("\n\n\n");
return;
}
/*------------------------------------------------------------
Asks the user if the name entered is correct
------------------------------------------------------------*/
void AskQuestion(void)
{
printf("\n\nIs this your name? (Y/N)"); /* prints the description */
scanf(" %c", &cName); /* get the input */
fflush(stdin); /* flush the CRLF */
return;
}
/*------------------------------------------------------------
Asks the user to enter in coursenumber
------------------------------------------------------------*/
void GetClass(void)
{
/***** Course Number *****/
char aCourseNumber[10];
printf("\n\nEnter one of the following course numbers. ");
printf("\n");
printf("(ABC101, HIS220, HOT707, ECO122, PLE888)\n ");
scanf(" %s", &aCourseNumber);
Font( aCourseNumber, courseNumber );
if(strcmp(courseNumber,"ABC101")==0)
{
printf("\n Welcome to class ABC101 \n");
printf("\n\n\n");
}
else if(strcmp(courseNumber,"HIS220")==0)
{
printf("\n Welcome to class HIS220 \n");
printf("\n\n\n");
}
else if(strcmp(courseNumber,"HOT707")==0)
{
printf("\n Welcome to class HOT707 \n");
printf("\n\n\n");
}
else if(strcmp(courseNumber,"EC0122")==0)
{
printf("\n Welcome to class ECO122 \n");
printf("\n\n\n");
}
else if(strcmp(courseNumber,"PLE888")==0)
{
printf("\n Welcome to class PLE888 \n");
printf("\n\n\n");
}
else
{
printf("\n That course number does not exist, please try again. \n");
printf("\n\n\n");
GetClass();
}
return;
}
/*------------------------------------------------------------
Performs grade calculation for each course
------------------------------------------------------------*/
void WeightedGrade(void)
{
if(strcmp(courseNumber,"ABC101")==0)
{
studentgrade = ((tests * .23) + (projects * .27) + (midtermexam * .20) + (finalexam * .30) + (bonus));
}
else if(strcmp(courseNumber,"HIS220")==0)
{
studentgrade = ((tests * .20) + (projects * .30) + (midtermexam * .25) + (finalexam * .25) + (bonus));
}
else if(strcmp(courseNumber,"HOT707")==0)
{
studentgrade = ((tests * .25) + (projects * .50) + (midtermexam * .15) + (finalexam * .10) + (bonus));
}
else if(strcmp(courseNumber,"EC0122")==0)
{
studentgrade =((tests * .25) + (projects * .25) + (midtermexam * .20) + (finalexam * .30) + (bonus));
}
else if(strcmp(courseNumber,"PLE888")==0)
{
studentgrade = ((tests * .30) + (projects * .20) + (midtermexam * .25) + (finalexam * .25) + (bonus));
}
system("cls");
return;
}
/*------------------------------------------------------------
Asks the user to enter in the student's name
------------------------------------------------------------*/
void NameofStudent(void)
{
printf("Enter the student's First Name. ");
scanf(" %13[^\n]",StudentfirstName);
fflush(stdin);
printf("Enter the student's Last Name. ");
scanf(" %13[^\n]",StudentlastName);
fflush(stdin);
strcpy(StudentName,StudentfirstName);
strcat(StudentName," ");
strcat(StudentName,StudentlastName);
system("cls");
return;
}
/*------------------------------------------------------------
Asks the user to enter in students' grades
------------------------------------------------------------*/
void GetStudentGrade(void)
{
printf(" Enter the grades of %s \n", StudentName);
printf("\n\n\n");
printf("Enter grade for Test1: ");
scanf(" %f", &test1);
printf("Enter grade for Test2: ");
scanf(" %f", &test2);
printf("Enter grade for Project1: ");
scanf(" %f", &project1);
printf("Enter grade for Project2: ");
scanf(" %f", &project2);
printf("Enter grade for Midterm: ");
scanf(" %f", &midterm);
printf("Enter grade for Final: ");
scanf(" %f", &final);
printf("Number of Bonus Projects: ");
scanf(" %d", &bonus);
fflush(stdin);
system("cls");
return;
}
/*------------------------------------------------------------
Performs student calculation
------------------------------------------------------------*/
void PerformCalc(void)
{
tests = (test1 + test2) / 2;
projects =(project1 + project2) / 2;
midtermexam =(midterm);
finalexam =(final);
if (bonus >= 1 && bonus <= 5)
{
bonus = 1;
}
else if (bonus >= 6 && bonus <= 9)
{
bonus = 3;
}
else if (bonus >= 10 && bonus <= 12)
{
bonus = 4;
}
else if(bonus >= 13)
{
bonus = 6;
}
else
{
bonus = 0;
}
return;
}
/*------------------------------------------------------------
Performs total calculation for all students
------------------------------------------------------------*/
void Totals(void)
{
if (studentgrade > 90)
studentA = studentA + 1;
else if (studentgrade >= 80 && studentgrade <= 89)
studentB = studentB + 1;
else if (studentgrade >= 72 && studentgrade <=79)
studentC = studentC + 1;
else if (studentgrade >= 70 && studentgrade <= 71)
studentD = studentD + 1;
else if (studentgrade <= 69)
studentF = studentF + 1;
totalstudents = (studentA + studentB + studentC + studentD + studentF);
totalaverage = totalaverage + studentgrade;
if (studentgrade > studentgrade)
StudentName = HighestAverage;
return;
}
/*------------------------------------------------------------
Displays the students' grade
------------------------------------------------------------*/
void GradeDisplay(void)
{
printf("Test Scores: %10.3f\n", tests);
printf("Project Scores: %10.3f\n", projects);
printf("Midterm Score: %10.3f\n", midtermexam);
printf("Final Score: %10.3f\n", finalexam);
printf("Bonus Points: %d\n", bonus);
printf("Student Grade: %10.3f\n", studentgrade);
fflush(stdin);
return;
}
/*------------------------------------------------------------
Asks the user a question
------------------------------------------------------------*/
void AskQuestion2(void)
{
printf("\n\nWould you like to enter in grades again? (Y/N)"); /* print description */
scanf(" %c", &cMore); /* get the input */
fflush(stdin); /* flush the CRLF */
return ;
}
/*------------------------------------------------------------
Prints A Line on Page
------------------------------------------------------------*/
void PrintAStarLine(void)
{
printf("******************************************************************************** \n");
printf("\n\n");
return;
}
/*------------------------------------------------------------
Displays the overall grade for each student
------------------------------------------------------------*/
void TotalPageDisplay(void)
{
totalaverage = totalaverage / (totalstudents);
system("cls");
PrintAStarLine();
printf("\t\t\t\tSchool Grade Totals \n");
printf("\n\n");
PrintAStarLine();
printf("Grade\t\t\t Total Students \n", studentandgrade);
printf("A\t\t\t %d\n", studentA);
printf("B\t\t\t %d\n", studentB);
printf("C\t\t\t %d\n", studentC);
printf("D\t\t\t %d\n", studentD);
printf("F\t\t\t %d\n", studentF);
printf("\n\n");
printf("__________________________________________________________________________ \n");
printf("GrandTotal number of Students: %d\n", totalstudents);
printf("\n");
printf("Overall average of all students: %6.2f\n", totalaverage);
printf("\n");
printf("Student with highest grade: %s\n", HighestAverage);
printf("\n");
return;
}