| | |
Displaying Average
![]() |
•
•
Join Date: Aug 2007
Posts: 58
Reputation:
Solved Threads: 0
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.
C Syntax (Toggle Plain Text)
/*+*+*+*+*+*+*+* 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; }
No, you learn nothing that way.
Get yourself a piece of paper and draw how it might look as a flow chart. Once you have done that, create a separate program to test your idea.
That way you know nothing else may be influencing the end result. If you are still stuck after that, post back here.
Get yourself a piece of paper and draw how it might look as a flow chart. Once you have done that, create a separate program to test your idea.
That way you know nothing else may be influencing the end result. If you are still stuck after that, post back here.
Last edited by iamthwee; Aug 22nd, 2007 at 3:53 pm.
Then why is quicksort so much better than bubblesort?
It's at least four or five times bigger, but in efficiency there's no comparison. The amount of code doesn't reflect efficiency; the quality of the code does. Quality isn't inversely proportional to size.
It's at least four or five times bigger, but in efficiency there's no comparison. The amount of code doesn't reflect efficiency; the quality of the code does. Quality isn't inversely proportional to size.
The truth does not change according to our ability to stomach it.
![]() |
Similar Threads
- displaying time (Java)
- Finding the average of numbers (C++)
- Floating point numbers (C)
- Only first out of three calculations is wrong (C++)
- how to do something special with this question (C++)
- displaying * in password entery (C++)
- PHP newbie, project feasibility (PHP)
- IE 5.0 not displaying pages properly (Web Browsers)
- Interpretation of an instructors C++ program... (C++)
Other Threads in the C Forum
- Previous Thread: Dynamic Binding In C
- Next Thread: can anyboby help me?
| Thread Tools | Search this Thread |
#include * ansi array arrays asterisks bash binarysearch centimeter changingto char character convert copyimagefile cprogramme creafecopyofanytypeoffileinc createprocess() database dynamic execv feet fgets file floatingpointvalidation fork function getlogicaldrivestrin givemetehcodez grade gtkwinlinux hacking histogram ide inches include incrementoperators infiniteloop initialization input interest intmain() iso kernel keyboard kilometer km license linked linkedlist linux list lists locate looping lowest matrix meter microsoft number oddnumber open opendocumentformat openwebfoundation owf pdf pointer pointers posix power probleminc process program programming radix recursion recv recvblocked research reversing segmentationfault sequential single socket socketprograming socketprogramming standard strchr string suggestions systemcall test threads turboc unix urboc user variable wab whythiscodecausesegmentationfault windowsapi






