fork download
  1. //Cecilia Rangel CSC5 Chapter 6, P.370, #4
  2. //
  3. /**************************************************************
  4.  *
  5.  * PRIME NUMBERS
  6.  * ____________________________________________________________
  7.  * This program will ask for the user to input a positive
  8.  * number, and the program determines if the number is a prime
  9.  * number
  10.  *
  11.  *_____________________________________________________________
  12.  * INPUT
  13.  * user input : Name of region, along with number of
  14.  * accidents in region
  15.  *
  16.  * OUTPUT
  17.  * Region : Region of city with lowest car accidents
  18.  *
  19.  *
  20.  *
  21.  **************************************************************/
  22. #include <iostream>
  23. #include <string>
  24. using namespace std;
  25.  
  26. //Global constants
  27.  
  28. const string NORTH = "North",
  29. SOUTH = "South",
  30. EAST = "East",
  31. WEST = "West",
  32. CENTRAL = "Central";
  33.  
  34. //Function Prototypes
  35.  
  36. int getNumAccidents(string);
  37. void findLowest(double, double, double, double, double);
  38. void checkifSmallest(double, double, double, double, double, string);
  39.  
  40. int main() {
  41. double N_total,
  42. S_total,
  43. E_total,
  44. W_total,
  45. C_total;
  46. //All being passed to getNumAccidents function to determine
  47. //number of acccidents in the region
  48.  
  49. N_total = getNumAccidents(NORTH);
  50. S_total = getNumAccidents(SOUTH);
  51. E_total = getNumAccidents(EAST);
  52. W_total = getNumAccidents(WEST);
  53. C_total = getNumAccidents(CENTRAL);
  54.  
  55. findLowest(N_total,
  56. S_total,
  57. E_total,
  58. W_total,
  59. C_total);
  60.  
  61. return 0;
  62. }
  63.  
  64. //************************************************************
  65. // getNumAccidents definition. This function gets the number *
  66. // of accidents for each region. *
  67. // ***********************************************************
  68.  
  69. int getNumAccidents(string region)
  70. {
  71. double num;
  72.  
  73. cout << "What is the car accidents reported in the " << region << " region "
  74. << "during the last year? ";
  75. cin >> num;
  76. cout << endl;
  77.  
  78. return num;
  79. }
  80.  
  81. //***********************************************************
  82. // findLowest definition. This function determines which *
  83. // region had the fewest accidents by passing it to the *
  84. // checkifSmallest function. *
  85. // **********************************************************
  86.  
  87. void findLowest(double N_total,
  88. double S_total,
  89. double E_total,
  90. double W_total,
  91. double C_total)
  92. {
  93. cout << "The region with the lowest car accident total is ";
  94.  
  95. checkifSmallest(N_total, S_total, E_total, W_total, C_total, NORTH);
  96. checkifSmallest(S_total, N_total, E_total, W_total, C_total, SOUTH);
  97. checkifSmallest(E_total, N_total, S_total, W_total, C_total, EAST);
  98. checkifSmallest(W_total, N_total, S_total, E_total, C_total, WEST);
  99. checkifSmallest(C_total, N_total, S_total, E_total, W_total, CENTRAL);
  100. cout << endl;
  101. }
  102.  
  103. //************************************************************
  104. // checkifSmallest definition. This function determines which*
  105. // is the smallest using a quad nested if statement. *
  106. // ***********************************************************
  107. void checkifSmallest(double total1,
  108. double total2,
  109. double total3,
  110. double total4,
  111. double total5,
  112. string region)
  113. {
  114. if (total1 < total2)
  115. {
  116. if (total1 < total3)
  117. {
  118. if (total1 < total4)
  119. {
  120. if (total1 < total5)
  121. {
  122. cout << region << ", with its total "
  123. << "being " << total1 << '.';
  124. }
  125. }
  126. }
  127. }
  128. }
  129.  
Success #stdin #stdout 0s 5324KB
stdin
500
700
130
415
585
stdout
What is the car accidents reported in the North region during the last year? 
What is the car accidents reported in the South region during the last year? 
What is the car accidents reported in the East region during the last year? 
What is the car accidents reported in the West region during the last year? 
What is the car accidents reported in the Central region during the last year? 
The region with the lowest car accident total is East, with its total being 130.