//Castulo Jason Quintero CSC5 Chapter 6, Pg. 370, #4
//
/**************************************************************************
*
* Determine Safest Driving Area
* ________________________________________________________________________
* This program takes as user input the accidents that have
* occured in each region and display the region with the
* least amount of accidents.
*
* Computation is based on formula:
* The findLowest function will compare the accidents of each
* region and display the region with the least amount of
* accidents.
* ________________________________________________________________________
* INPUT
* crash : The amount of accidents in the region
*
* OUTPUT
* accident1 : Accidents in the north region
* accident2 : Accidents in the east region
* accident3 : Accidents in the south region
* accident4 : Accidents in the west region
* accident5 : Accidents in the central region
* The output will be the region with the least amount of
* accidents.
*
*************************************************************************/
#include <iostream>
#include <iomanip>
using namespace std;
// Prototypes
int getNumAccidents(string);
void findLowest(int, int, int, int, int);
int main()
{
// String variables to hold the regions names.
string name1 = "North";
string name2 = "East";
string name3 = "South";
string name4 = "West";
string name5 = "Central";
// Variables to hold the accidents of each region.
int accident1;
int accident2;
int accident3;
int accident4;
int accident5;
// Tells the user what will happen
cout << "Enter the number of accidents in each region and the "
<< "region with the least amount of accidents will be presented.\n";
// Function that is passed region name, validates, and returns the
// value to the variable associated with the region.
accident1 = getNumAccidents(name1);
accident2 = getNumAccidents(name2);
accident3 = getNumAccidents(name3);
accident4 = getNumAccidents(name4);
accident5 = getNumAccidents(name5);
// Function that is passed the values and checks to see which
// region had the least amount of accidents.
findLowest(accident1, accident2, accident3, accident4, accident5);
return 0;
}
// User enters the accidents of each region and validates it.
int getNumAccidents(string regionname)
{
int crash;
cout << "Please enter the number of accidents in the " << regionname
<< " region: " << endl;
cin >> crash;
while (crash < 0)
{
cout << "Please enter a value greater than zero: ";
cin >> crash;
}
return crash;
}
// Determines which region has the least amount of accidents.
void findLowest (int accident1, int accident2, int accident3,
int accident4, int accident5)
{
if (accident1 < accident2 && accident1 < accident3 &&
accident1 < accident4 && accident1 < accident5)
{
cout << "The North region has the least amount of accidents!"
<< " With only " << accident1 << " accident(s).";
}
else if (accident2 < accident1 && accident2 < accident3
&& accident2 < accident4 && accident2 < accident5)
{
cout << "The East region has the least amount of accidents!"
<< " With only " << accident2 << " accident(s).";
}
else if (accident3 < accident1 && accident3 < accident2
&& accident3 < accident4 && accident3 < accident5)
{
cout << "The South region has the least amount of accidents!"
<< " With only " << accident3 << " accident(s).";
}
else if (accident4 < accident1 && accident4 < accident2
&& accident4 < accident3 && accident4 < accident5)
{
cout << "The West region has the least amount of accidents!"
<< " With only " << accident4 << " accident(s).";
}
else
{
cout << "The Central region has the least amount of accidents!"
<< " With only " << accident5 << " accident(s).";
}
}