1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
This program will ask the user for the number of accidents for that year.
It will then use two functions to calculate the area with the lowest
accidents and displays the name of the area and the number of accidents.
*/
#include <iostream>
#include <cstring>
using namespace std;
//Function prototype
int numAccident(string regionName);
void findLowest(int north, int south, int east, int west, int central);
string regionName;
int main()
{
// Variables.
char again; // Using charcaters.
int north, south, east, west, central;
do
{
cout << "Accidents for the North Region: ";
north = numAccident(regionName);
cout << "Accindents for the South Region: ";
south = numAccident(regionName);
cout << "Accidents for the East Region: ";
east = numAccident(regionName);
cout << "Accidents for the West Region: ";
west = numAccident(regionName);
cout << "Accidents for the Central Region: ";
central = numAccident(regionName);
// Aks user if they would like try again.
cout << "Would you like to try again? (y or n)";
cin >> again;
} while (again == 'y' || again == 'Y');
system("pause");
return 0;
}
/********************************************************************
* numAccidents Function *
* This function is passed the name of the region. Its asks the user *
* for the number of traffic accidents reported in that region during*
* the lst year, validates the input, then returns it *
* ******************************************************************/
int numAccident(string regionName)
{
int accident;
cout << regionName << "Accidents: ";
cin >> accident;
if (accident < 0)
{
cout << "You cannot have less than zero accidents.\n";
}
else
return accident;
}
/************************************************************************
* void findLowest Function *
* This function is passed the five accident totals.It will determine *
* which is the smallest and prints the name of the region, along with *
* its accident figure. *
************************************************************************/
void findLowest(int north, int south, int east, int west, int central)
{
if (north < south && south < east && east < west && west < central)
cout << "The Central Region came in the lowest with " << central << " accidents." << endl;
else if (south < north && north < east && east < central && central < west)
cout << "The west Region came in the lowest with " << west << " accidents." << endl;
else if (central < south && south < north && north < west && west < east)
cout << "The East Region came in with the lowest with " << east << " accidents." << endl;
else if (east < north && north < west && west < central && central < south)
cout << "The South Region came in the lowset with " << south << "accidents." << endl;
else
cout << "The North Region came in the lowest with" << north << " accidents." << endl;
}
|