fork download
  1. #include <stdio.h>
  2.  
  3. // **************************************************
  4. // Function: calcLetterGrade
  5. //
  6. // Description: Given a test score - will return the letter grade
  7. //
  8. //
  9. // Parameters: score - the score in number for the test
  10. //
  11. // Returns: A-F for the letter grade. I for invalid
  12. //
  13. // ***************************************************
  14. char calcLetterGrade (int score)
  15. {
  16. char result; /* letter grade result */
  17.  
  18. // Check for invalid score
  19. if (score > 100 || score < 0)
  20. {
  21. return 'I'; //Invalid
  22. }
  23.  
  24. // map score to letter grade
  25. if (score >= 90)
  26. result = 'A';
  27. else if (score >= 80)
  28. result = 'B';
  29. else if (score >= 70)
  30. result = 'C';
  31. else if (score >= 60)
  32. result = 'D';
  33. else
  34. result = 'F';
  35.  
  36.  
  37. return result;
  38. }
  39.  
  40.  
  41. struct countyTotals
  42. {
  43. int totalCorkCodes;
  44. int totalDublinCodes;
  45. int totalGalwayCodes;
  46. int totalLimerickCodes;
  47. int totalTiperaryCodes;
  48. int totalWaterfordCodes;
  49. int totalInvalidCountryCodes;
  50. };
  51. // **************************************************
  52. // Function: freqOfIrishCounties
  53. //
  54. // Description: Frequency calculator for Irish Couties
  55. //
  56. //
  57. // Parameters: countyArrayList - An array of county charachter codes
  58. // size - length of the array
  59. //
  60. // Returns: the countryTotals struct, populated with the correct number
  61. //
  62. // ***************************************************
  63. struct countyTotals freqOfIrishCounties(char countyArrayList[], int size)
  64. {
  65.  
  66. struct countyTotals myCountyTotals = {0,0,0,0,0,0,0}; // holds the country counts
  67. // and initializes them to zero
  68.  
  69. // Review each of the county codes in the array
  70. for(int i = 0; i < size; i++)
  71. {
  72. // increments the total of the current county character value
  73. // ... note that case does not matter, both upper and lower count the same
  74. // towards the totals
  75. switch (countyArrayList[i])
  76. {
  77. case 'C':
  78. case 'c':
  79. myCountyTotals.totalCorkCodes++;
  80. break;
  81. case 'D':
  82. case 'd':
  83. myCountyTotals.totalDublinCodes++;
  84. break;
  85. case 'G':
  86. case 'g':
  87. myCountyTotals.totalGalwayCodes++;
  88. break;
  89. case 'L':
  90. case 'l':
  91. myCountyTotals.totalLimerickCodes++;
  92. break;
  93. case 'T':
  94. case 't':
  95. myCountyTotals.totalTiperaryCodes++;
  96. break;
  97. case 'W':
  98. case 'w':
  99. myCountyTotals.totalWaterfordCodes++;
  100. break;
  101. default:
  102. myCountyTotals.totalInvalidCountryCodes++;
  103.  
  104. } // switch
  105. } // for
  106.  
  107. return (myCountyTotals);
  108.  
  109. } // freqOfIrishCounties
  110.  
  111.  
  112.  
  113. int min(int value1, int value2, int value3, int value4)
  114. {
  115.  
  116.  
  117. int min4 = ((value1 < value2) && (value1 < value3) && (value1 < value4)) ? value1 : // value1 is the smallest
  118. ((value2 < value1) && (value2 < value3) && (value2 < value4)) ? value2 : // value2 is smallest
  119. ((value3 < value1) && (value3 < value2) && (value3 < value4)) ? value3 : // value3 is smallest
  120. value4; // otherwise value4 is smallest
  121. return min4;
  122. }
  123.  
  124.  
  125. int main(void) {
  126. int arr[] = {1,1,1,2,2,2};
  127. char countyCodes[] = {'C', 'c', 'E', 'G', 'G', 'L', 'l', 'l', 'T', 'W', 'J', 'd'};
  128. printf("area is: %i", freqOfIrishCounties(countyCodes, 12).totalWaterfordCodes);
  129. return 0;
  130. }
  131.  
Success #stdin #stdout 0s 5284KB
stdin
Standard input is empty
stdout
area is: 1