// Gage Alvarez CS1A Chapter 6 P. 370, 4
/**************************************************************
*
* DETERMINE MINIMAL ACCIDENTS AREA
* ____________________________________________________________
* Description
* Program determines the safest region of a major city between north, south, east, west, and central.
*
* This program accepts the number of reported accidents for several regions of
* a city. The program reports the region with the smallest number of reported
* accidents and the number of accidents in that region.
* ____________________________________________________________
* INPUT
* regions: number of regions in the given city
* accidents: the number of accidents in the given city
*
* OUTPUT
* direction: the region with the lowest number of accidents
* lowest: the number of accidents in the above region
*
**************************************************************/
#include <iostream>
#include <vector>
using namespace std;
int getNumAccidents(string region);
void findLowest(int north, int south, int west, int east, int central);
int main() {
//Data Dictionary
int accidentsN;
int accidentsS;
int accidentsW;
int accidentsE;
int accidentsC;
//Input
accidentsN = getNumAccidents("northern");
accidentsS = getNumAccidents("southern");
accidentsW = getNumAccidents("western");
accidentsE = getNumAccidents("eastern");
accidentsC = getNumAccidents("central");
//Processs
findLowest(accidentsN, accidentsS, accidentsW, accidentsE, accidentsC);
return 0;
}
int getNumAccidents(string region)
{
//This function accepts a number of accidents(validated to be greater than 0)
// for a specified region, and returns that number to the calling program.
int numAccidents;
cout << "Enter the number of accidents for the " << region << " region" << endl;
cin >> numAccidents;
while (numAccidents < 0) {
cout << "Invalid input, number of accidents cannot be less than 0" << endl;
cin >> numAccidents;
}
return numAccidents;
}
void findLowest(int north, int south, int west, int east, int central) {
int lowest;
lowest = north;
if (lowest <= north)
if (lowest <= south)
if (lowest <= west)
if (lowest <= east)
if (lowest <= central)
lowest = lowest;
else
lowest = central;
else
lowest = east;
else
lowest = west;
else
lowest = south;
else
lowest = north;
cout << "Line #83: " << lowest;
// vector<int> allAccidents {north, south, west, east, central};
// vector<string> directions {"north", "south", "west", "east", "central"};
// int lowest = allAccidents[0];
// string direction = directions[0];
// for (int i = 0; i < allAccidents.size(); i++) {
// if (allAccidents[i] < lowest) {
// lowest = allAccidents[i];
// direction = directions[i];
// }
// }
// cout <<"the " << direction << " had the least accidents, with only "
// << lowest << " accidents." << endl;
}