//Vanessa Ramirez CSC5 Chapter 6, P. 370, #4
//
/*******************************************************************************
* FEWEST AUTOMOBILE ACCIDENTS
* _____________________________________________________________________________
* This program which five geographic regions had the fewest reported automobile
* accidents. This program asks the user for the accident total in each region,
* valdiates teh input, and displays the safest region.
* _____________________________________________________________________________
* INPUT
* north - Number of accidents in the north region
* south - Number of accidents in the south region
* east - Number of accidents in the east region
* west - Number of accidents in the west region
* central - Number of accidents in the central region
*
* OUTPUT
* safestRegion - Region with the fewest accidents
* lowest - Lowest number of accidents
******************************************************************************/
#include <iostream>
#include <string>
using namespace std;
//Function prototype
int getNumAccidents (string region);
void findLowest (int north, int south, int east, int west, int central);
int main()
{
// Declare variables
int north;
int south;
int east;
int west;
int central;
// Get accident totals for each region
north = getNumAccidents("North");
south = getNumAccidents("South");
east = getNumAccidents("East");
west = getNumAccidents("West");
central = getNumAccidents("Central");
// Find and display the region with fewest accidents
findLowest(north, south, east, west, central);
return 0;
}
// getNumAccidents
// Ask for region's accident total., validate the input, and returns the number
// of accidents.
//
//******************************************************************************
int getNumAccidents(string region)
{
int accidents;
cout << "Enter the number of accidents for the "
<< region << " region: ";
cin >> accidents;
while (accidents < 0)
{
cout << "Accidents cannot be less than 0." << endl;
cout << "Enter the number of accidents for the "
<< region << " region: ";
cin >> accidents;
}
return accidents;
}
void findLowest(int north, int south, int east, int west, int central)
{
int lowest;
string safestRegion;
//Assume the north region has the fewest accidents
lowest = north;
safestRegion = "North";
if (south < lowest)
{
lowest = south;
safestRegion = "South";
}
if (east < lowest)
{
lowest = east;
safestRegion = "East";
}
if (west < lowest)
{
lowest = west;
safestRegion = "West";
}
if (central < lowest)
{
lowest = central;
safestRegion = "Central";
}
// Display the results
cout << endl << "Safest Driving Area: " << safestRegion << endl;
cout << "Number of accidents: " << lowest << endl;
}