//Cameron Pham CS1A Chapter 6, p. 370, #4
//
/******************************************************************************
* DETERMINE SAFEST DRIVING AREA
* ______________________________________________________________________________
* This program accepts an integer value for a guess of a random number. It
* Generates a random number.
* ______________________________________________________________________________
* INPUT
* Number of accidents // Number of automobile accidents reported in given region
*
* OUTPUT
* Safest driving area // Region with the smallest number of automobile accidents
*
*******************************************************************************/
#include <iostream>
#include <cmath>
using namespace std;
// Set Function Prototypes
int getNumAccidents(string region);
void findLowest(int north, int south, int east, int west, int central);
int main()
{
// Declare Variables
int north; // Number of accidents in north region
int south; // Number of accidents in south region
int east; // Number of accidents in east region
int west; // Number of accidents in west region
int central; // Number of accidents in central region
int lowest; // Lowest number of accidents
// Get Accident Totals
north = getNumAccidents("North");
south = getNumAccidents("South");
east = getNumAccidents("East");
west = getNumAccidents("West");
central = getNumAccidents("Central");
// Display the Safest Driving Area
findLowest(north, south, east, west, central);
return 0;
}
// Define the Prototypes
int getNumAccidents(string region)
{
int accidents;
cout << "Please enter the number of accidents in " << region;
cout << " region: ";
cin >> accidents;
cout << endl;
// Validate Input
while(accidents < 0)
{
cout << "Enter a value of 0 or greater." << endl;
cin >> accidents;
}
return accidents;
}
void findLowest(int north, int south, int east, int west, int central)
{
int lowest;
string safest;
// Set North as the Base for Lowest Value
lowest = north;
safest = "North";
// Test Regions for Values
if(south < lowest)
{
lowest = south;
safest = "South";
}
if(east < lowest)
{
lowest = east;
safest = "East";
}
if(west < lowest)
{
lowest = west;
safest = "West";
}
if(central < lowest)
{
lowest = central;
safest = "Central";
}
// Display Safest Region
cout << "The safest region to drive in is the " << safest << " region.";
if(lowest != 1)
{
cout << endl << "This region has had " << lowest << " accidents.";
}
if(lowest == 1)
{
cout << endl << "This region has had " << lowest << " accident.";
}
}