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 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
|
#include <iostream>
#include <iomanip>
using namespace std;
/*
Function Prototypes
*/
int getNumAccidents (int&);
void findLowest (int, int, int, int, int);
/*
Main Function*/
int main()
{
int north, south, east, west, central;
// call getNumAccidents
north = getNumAccidents(north);
south = getNumAccidents(south);
east = getNumAccidents(east);
west = getNumAccidents(west);
central = getNumAccidents(central);
// call findLowest to find and display the lowest region
findLowest(north, south, east, west, central);
return 0;
} // end of main functin
/* getNumAccidents
*/
int north, south, east, west, central;
int getNumAccidents(int&)
{
cout << "Enter the number of accidents in each region: \n"
<< "North : ";
cin >> north;
while (north < 0)
{
cout << "The number of accidents canot be negative" << endl
<< "Please re-enter the number of accidents: ";
cin >> north;
}
cout << "South : ";
cin >> south;
while (south < 0)
{
cout << "The number of accidents canot be negative" << endl
<< "Please re-enter the number of accidents: ";
cin >> south;
}
cout << "East : ";
cin >> east;
while (east < 0)
{
cout << "The number of accidents canot be negative" << endl
<< "Please re-enter the number of accidents: ";
cin >> east;
}
cout << "West : ";
cin >> west;
while (west < 0)
{
cout << "The number of accidents canot be negative" << endl
<< "Please re-enter the number of accidents: ";
cin >> west;
}
cout << "Central : ";
cin >> central;
while (central < 0)
{
cout << "The number of accidents canot be negative" << endl
<< "Please re-enter the number of accidents: ";
cin >> central;
}
return north, south, east, west, central;
}
/* findLowest()
*/
void findLowest (int north, int south, int east, int west, int central)
{
int lowest = north;
if (south < lowest)
lowest = south;
if (east < lowest)
lowest = east;
if (west < lowest)
lowest = west;
if (central < lowest)
lowest = central;
// Display the region with the least amount of accidents
if (lowest == north)
cout << "The North region had the lowest amount of accidents. \n"
<< "Only " << lowest << " accidents were reported. \n";
else if (lowest == south)
cout << "The South region had the lowest amount of accidents. \n"
<< "Only " << lowest << " accidents were reported. \n";
else if (lowest == east)
cout << "The East region had the lowest amount of accidents. \n"
<< "Only " << lowest << " accidents were reported. \n";
else if (lowest == west)
cout << "The West region had the lowest amount of accidents. \n"
"Only " << lowest << " accidents were reported. \n";
else if (lowest == central)
cout << "The Central region had the lowest amount of accidents. \n"
<< "Only " << lowest << " accidents were reported. \n";
} // end of findLowest
|