Displaying Average

Reply

Join Date: Aug 2007
Posts: 58
Reputation: NycNessyness is an unknown quantity at this point 
Solved Threads: 0
NycNessyness NycNessyness is offline Offline
Junior Poster in Training

Displaying Average

 
0
  #1
Aug 22nd, 2007
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.
  1. /*+*+*+*+*+*+*+* Preprocessor Directives *+*+*+*+*+*+*+*/
  2.  
  3.  
  4. #include <stdio.h>
  5. #include <string.h>
  6. #include <iostream>
  7.  
  8.  
  9.  
  10. /*+*+*+*+*+*+*+* Function Prototypes *+*+*+*+*+*+*+*/
  11.  
  12. void WelcomeInfo (void); /* Welcomes the user */
  13. void AskQuestion(void); /* Asks the user a question */
  14. void GetClass(void); /* Gets the input */
  15. void GetStudentGrade(void);
  16. void NameofStudent(void);
  17. void PerformCalc(void); /* Performs the calculation */
  18. void GradeDisplay(void);
  19. void Totals(void);
  20. void WeightedGrade(void);
  21. void AskQuestion2(void); /* Asks the user a question */
  22. void PrintAStarLine(void);
  23. void TotalPageDisplay(void);
  24.  
  25. /*+*+*+*+*+*+*+* Variables *+*+*+*+*+*+*+*/
  26.  
  27. void Font( const char *Input, char *Output )
  28. {
  29.  
  30. int Length, Size;
  31. Length = strlen( Input );
  32.  
  33. for( Size=0; Size<Length; Size++ )
  34. {
  35. if( Input[Size]>='a' && Input[Size]<='z' )
  36. Output[Size]=Input[Size]-32;
  37. else
  38. Output[Size]=Input[Size];
  39. }
  40.  
  41. Output[Size]=0x00;
  42.  
  43. }
  44.  
  45.  
  46. float test1;
  47. float test2;
  48. float project1;
  49. float project2;
  50. float midterm;
  51. float final;
  52. float tests;
  53. float projects;
  54. float midtermexam;
  55. float finalexam;
  56. float studentgrade;
  57.  
  58.  
  59. int bonus = 0;
  60. float totalaverage;
  61. int totalstudents;
  62.  
  63. int studentA = 0;
  64. int studentB = 0;
  65. int studentC = 0;
  66. int studentD = 0;
  67. int studentF = 0;
  68.  
  69. char newline;
  70.  
  71. char courseNumber[10];
  72. char cName;
  73. char cMore;
  74. char Name[30];
  75.  
  76. char StudentName[30];
  77. char StudentfirstName[15];
  78. char StudentlastName[15];
  79. char studentandgrade;
  80. char HighestAverage;
  81. char K;
  82.  
  83.  
  84. /*+*+*+*+*+*+*+*^ The Main Module ^*+*+*+*+*+*+*+*/
  85.  
  86. main()
  87. {
  88.  
  89.  
  90. cName = 'N';
  91.  
  92.  
  93. do
  94. {
  95. WelcomeInfo();
  96.  
  97.  
  98. AskQuestion();
  99.  
  100.  
  101. } while ((cName != 'Y') && (cName != 'y'));
  102.  
  103.  
  104. cMore = 'Y';
  105. do
  106. {
  107.  
  108.  
  109. GetClass();
  110.  
  111. NameofStudent();
  112. system("cls");
  113. GetStudentGrade();
  114. system("cls");
  115. PerformCalc();
  116. WeightedGrade();
  117. system("cls");
  118. GradeDisplay();
  119.  
  120. AskQuestion2();
  121. Totals();
  122.  
  123.  
  124. }while ((cMore != 'N') && (cMore != 'n')); /* It will loop until user enter N */
  125.  
  126.  
  127. TotalPageDisplay();
  128.  
  129.  
  130.  
  131. return 0;
  132. }
  133.  
  134. /*------------------------------------------------------------
  135. Welcomes the user
  136.   ------------------------------------------------------------*/
  137.  
  138. void WelcomeInfo (void)
  139. {
  140.  
  141.  
  142. printf("Enter your name please. ");
  143. scanf( "%[^\n]%c", Name, &newline );
  144.  
  145. printf("\n\n\n");
  146.  
  147. printf("\t\t\t\t Welcome %s", Name);
  148. printf("\n\n\n");
  149.  
  150. return;
  151. }
  152.  
  153. /*------------------------------------------------------------
  154. Asks the user if the name entered is correct
  155.   ------------------------------------------------------------*/
  156.  
  157. void AskQuestion(void)
  158. {
  159. printf("\n\nIs this your name? (Y/N)"); /* prints the description */
  160. scanf(" %c", &cName); /* get the input */
  161. fflush(stdin); /* flush the CRLF */
  162.  
  163.  
  164. return;
  165. }
  166.  
  167.  
  168.  
  169. /*------------------------------------------------------------
  170. Asks the user to enter in coursenumber
  171.   ------------------------------------------------------------*/
  172.  
  173. void GetClass(void)
  174. {
  175.  
  176. /***** Course Number *****/
  177.  
  178.  
  179.  
  180. char aCourseNumber[10];
  181.  
  182.  
  183. printf("\n\nEnter one of the following course numbers. ");
  184. printf("\n");
  185. printf("(ABC101, HIS220, HOT707, ECO122, PLE888)\n ");
  186. scanf(" %s", &aCourseNumber);
  187.  
  188. Font( aCourseNumber, courseNumber );
  189.  
  190.  
  191. if(strcmp(courseNumber,"ABC101")==0)
  192. {
  193. printf("\n Welcome to class ABC101 \n");
  194. printf("\n\n\n");
  195. }
  196. else if(strcmp(courseNumber,"HIS220")==0)
  197. {
  198. printf("\n Welcome to class HIS220 \n");
  199. printf("\n\n\n");
  200. }
  201. else if(strcmp(courseNumber,"HOT707")==0)
  202. {
  203. printf("\n Welcome to class HOT707 \n");
  204. printf("\n\n\n");
  205. }
  206. else if(strcmp(courseNumber,"EC0122")==0)
  207. {
  208. printf("\n Welcome to class ECO122 \n");
  209. printf("\n\n\n");
  210. }
  211. else if(strcmp(courseNumber,"PLE888")==0)
  212. {
  213. printf("\n Welcome to class PLE888 \n");
  214. printf("\n\n\n");
  215. }
  216. else
  217. {
  218. printf("\n That course number does not exist, please try again. \n");
  219. printf("\n\n\n");
  220. GetClass();
  221. }
  222. return;
  223. }
  224.  
  225.  
  226. /*------------------------------------------------------------
  227. Performs grade calculation for each course
  228.   ------------------------------------------------------------*/
  229.  
  230. void WeightedGrade(void)
  231. {
  232. if(strcmp(courseNumber,"ABC101")==0)
  233. {
  234. studentgrade = ((tests * .23) + (projects * .27) + (midtermexam * .20) + (finalexam * .30) + (bonus));
  235. }
  236. else if(strcmp(courseNumber,"HIS220")==0)
  237. {
  238. studentgrade = ((tests * .20) + (projects * .30) + (midtermexam * .25) + (finalexam * .25) + (bonus));
  239. }
  240. else if(strcmp(courseNumber,"HOT707")==0)
  241. {
  242. studentgrade = ((tests * .25) + (projects * .50) + (midtermexam * .15) + (finalexam * .10) + (bonus));
  243. }
  244. else if(strcmp(courseNumber,"EC0122")==0)
  245. {
  246. studentgrade =((tests * .25) + (projects * .25) + (midtermexam * .20) + (finalexam * .30) + (bonus));
  247. }
  248. else if(strcmp(courseNumber,"PLE888")==0)
  249. {
  250. studentgrade = ((tests * .30) + (projects * .20) + (midtermexam * .25) + (finalexam * .25) + (bonus));
  251. }
  252.  
  253. system("cls");
  254.  
  255. return;
  256.  
  257. }
  258.  
  259.  
  260. /*------------------------------------------------------------
  261. Asks the user to enter in the student's name
  262.   ------------------------------------------------------------*/
  263.  
  264. void NameofStudent(void)
  265. {
  266.  
  267.  
  268. printf("Enter the student's First Name. ");
  269. scanf(" %13[^\n]",StudentfirstName);
  270. fflush(stdin);
  271.  
  272. printf("Enter the student's Last Name. ");
  273. scanf(" %13[^\n]",StudentlastName);
  274. fflush(stdin);
  275.  
  276. strcpy(StudentName,StudentfirstName);
  277. strcat(StudentName," ");
  278. strcat(StudentName,StudentlastName);
  279. system("cls");
  280.  
  281.  
  282. return;
  283.  
  284. }
  285.  
  286.  
  287. /*------------------------------------------------------------
  288. Asks the user to enter in students' grades
  289.   ------------------------------------------------------------*/
  290.  
  291. void GetStudentGrade(void)
  292. {
  293. printf(" Enter the grades of %s \n", StudentName);
  294. printf("\n\n\n");
  295.  
  296.  
  297. printf("Enter grade for Test1: ");
  298. scanf(" %f", &test1);
  299.  
  300.  
  301. printf("Enter grade for Test2: ");
  302. scanf(" %f", &test2);
  303.  
  304. printf("Enter grade for Project1: ");
  305. scanf(" %f", &project1);
  306.  
  307. printf("Enter grade for Project2: ");
  308. scanf(" %f", &project2);
  309.  
  310. printf("Enter grade for Midterm: ");
  311. scanf(" %f", &midterm);
  312.  
  313. printf("Enter grade for Final: ");
  314. scanf(" %f", &final);
  315.  
  316. printf("Number of Bonus Projects: ");
  317. scanf(" %d", &bonus);
  318.  
  319.  
  320. fflush(stdin);
  321. system("cls");
  322. return;
  323. }
  324.  
  325.  
  326. /*------------------------------------------------------------
  327. Performs student calculation
  328.   ------------------------------------------------------------*/
  329.  
  330.  
  331. void PerformCalc(void)
  332. {
  333.  
  334. tests = (test1 + test2) / 2;
  335. projects =(project1 + project2) / 2;
  336. midtermexam =(midterm);
  337. finalexam =(final);
  338. if (bonus >= 1 && bonus <= 5)
  339. {
  340.  
  341. bonus = 1;
  342. }
  343. else if (bonus >= 6 && bonus <= 9)
  344. {
  345. bonus = 3;
  346. }
  347. else if (bonus >= 10 && bonus <= 12)
  348. {
  349. bonus = 4;
  350. }
  351. else if(bonus >= 13)
  352. {
  353. bonus = 6;
  354. }
  355. else
  356. {
  357. bonus = 0;
  358. }
  359.  
  360.  
  361. return;
  362.  
  363. }
  364.  
  365. /*------------------------------------------------------------
  366. Performs total calculation for all students
  367.   ------------------------------------------------------------*/
  368.  
  369. void Totals(void)
  370. {
  371.  
  372. if (studentgrade > 90)
  373. studentA = studentA + 1;
  374.  
  375. else if (studentgrade >= 80 && studentgrade <= 89)
  376. studentB = studentB + 1;
  377.  
  378. else if (studentgrade >= 72 && studentgrade <=79)
  379. studentC = studentC + 1;
  380.  
  381.  
  382. else if (studentgrade >= 70 && studentgrade <= 71)
  383. studentD = studentD + 1;
  384.  
  385.  
  386. else if (studentgrade <= 69)
  387. studentF = studentF + 1;
  388.  
  389.  
  390.  
  391.  
  392. totalstudents = (studentA + studentB + studentC + studentD + studentF);
  393. totalaverage = totalaverage + studentgrade;
  394.  
  395. if (studentgrade > studentgrade)
  396. StudentName = HighestAverage;
  397.  
  398.  
  399.  
  400. return;
  401.  
  402. }
  403.  
  404.  
  405. /*------------------------------------------------------------
  406. Displays the students' grade
  407.   ------------------------------------------------------------*/
  408.  
  409. void GradeDisplay(void)
  410. {
  411. printf("Test Scores: %10.3f\n", tests);
  412. printf("Project Scores: %10.3f\n", projects);
  413. printf("Midterm Score: %10.3f\n", midtermexam);
  414. printf("Final Score: %10.3f\n", finalexam);
  415. printf("Bonus Points: %d\n", bonus);
  416. printf("Student Grade: %10.3f\n", studentgrade);
  417. fflush(stdin);
  418.  
  419. return;
  420.  
  421. }
  422.  
  423. /*------------------------------------------------------------
  424. Asks the user a question
  425.   ------------------------------------------------------------*/
  426.  
  427. void AskQuestion2(void)
  428. {
  429. printf("\n\nWould you like to enter in grades again? (Y/N)"); /* print description */
  430. scanf(" %c", &cMore); /* get the input */
  431. fflush(stdin); /* flush the CRLF */
  432.  
  433.  
  434. return ;
  435. }
  436.  
  437. /*------------------------------------------------------------
  438. Prints A Line on Page
  439.   ------------------------------------------------------------*/
  440.  
  441. void PrintAStarLine(void)
  442.  
  443. {
  444.  
  445. printf("******************************************************************************** \n");
  446. printf("\n\n");
  447.  
  448. return;
  449.  
  450. }
  451.  
  452. /*------------------------------------------------------------
  453. Displays the overall grade for each student
  454.   ------------------------------------------------------------*/
  455.  
  456.  
  457. void TotalPageDisplay(void)
  458. {
  459. totalaverage = totalaverage / (totalstudents);
  460.  
  461. system("cls");
  462. PrintAStarLine();
  463. printf("\t\t\t\tSchool Grade Totals \n");
  464. printf("\n\n");
  465. PrintAStarLine();
  466. printf("Grade\t\t\t Total Students \n", studentandgrade);
  467. printf("A\t\t\t %d\n", studentA);
  468. printf("B\t\t\t %d\n", studentB);
  469. printf("C\t\t\t %d\n", studentC);
  470. printf("D\t\t\t %d\n", studentD);
  471. printf("F\t\t\t %d\n", studentF);
  472. printf("\n\n");
  473.  
  474.  
  475.  
  476. printf("__________________________________________________________________________ \n");
  477.  
  478. printf("GrandTotal number of Students: %d\n", totalstudents);
  479. printf("\n");
  480.  
  481. printf("Overall average of all students: %6.2f\n", totalaverage);
  482. printf("\n");
  483.  
  484. printf("Student with highest grade: %s\n", HighestAverage);
  485. printf("\n");
  486.  
  487. return;
  488.  
  489. }
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,264
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: Displaying Average

 
0
  #2
Aug 22nd, 2007
> I'm currently having problems concerning displaying a student with the highest grade.

It's pretty obvious.

Create a value at the start of the loop.

Go through each value and if the current value is greater than the original update it. At the end you should be left with the biggest one.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 322
Reputation: Hamrick will become famous soon enough Hamrick will become famous soon enough 
Solved Threads: 33
Hamrick's Avatar
Hamrick Hamrick is offline Offline
Posting Whiz

Re: Displaying Average

 
0
  #3
Aug 22nd, 2007
It's pretty obvious.
Just because it's obvious to you doesn't make it obvious to everyone.
The truth does not change according to our ability to stomach it.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 58
Reputation: NycNessyness is an unknown quantity at this point 
Solved Threads: 0
NycNessyness NycNessyness is offline Offline
Junior Poster in Training

Re: Displaying Average

 
0
  #4
Aug 22nd, 2007
How should I go about doing so, may you show me an example please. Also where I have
"if (studentgrade > studentgrade)
StudentName = HighestAverage;"
doesnt work. It says cant convert from char to char.
Last edited by NycNessyness; Aug 22nd, 2007 at 3:51 pm.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,264
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: Displaying Average

 
0
  #5
Aug 22nd, 2007
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.
Last edited by iamthwee; Aug 22nd, 2007 at 3:53 pm.
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 170
Reputation: TkTkorrovi is on a distinguished road 
Solved Threads: 11
TkTkorrovi's Avatar
TkTkorrovi TkTkorrovi is offline Offline
Junior Poster

Re: Displaying Average

 
0
  #6
Aug 22nd, 2007
Hehe, the size of this code is already most of my gtk asteroids, this shows how inefficient the code may be...
Knowledge is regarded by the fool as ignorance, and the things that are profitable are to him hurtful. He liveth in death. -- Thoth the Atlantean
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 322
Reputation: Hamrick will become famous soon enough Hamrick will become famous soon enough 
Solved Threads: 33
Hamrick's Avatar
Hamrick Hamrick is offline Offline
Posting Whiz

Re: Displaying Average

 
0
  #7
Aug 22nd, 2007
Since when does size reflect efficiency?
The truth does not change according to our ability to stomach it.
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 170
Reputation: TkTkorrovi is on a distinguished road 
Solved Threads: 11
TkTkorrovi's Avatar
TkTkorrovi TkTkorrovi is offline Offline
Junior Poster

Re: Displaying Average

 
0
  #8
Aug 22nd, 2007
Concerning the code, it often does...
Knowledge is regarded by the fool as ignorance, and the things that are profitable are to him hurtful. He liveth in death. -- Thoth the Atlantean
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 322
Reputation: Hamrick will become famous soon enough Hamrick will become famous soon enough 
Solved Threads: 33
Hamrick's Avatar
Hamrick Hamrick is offline Offline
Posting Whiz

Re: Displaying Average

 
0
  #9
Aug 22nd, 2007
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.
The truth does not change according to our ability to stomach it.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,264
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: Displaying Average

 
0
  #10
Aug 22nd, 2007
There is no need to hijack other people's thread. If you want to discuss your opinons use private mail.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC