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
|
#include <iostream>
#include <string>
using namespace std;
int getNumAccidents(string);
void findLowest(int, int, int, int, int);
int main()
{
//Variables
int choice;
//Asks user to enter choice
cout << "Please select on of the choices below: " << endl;
cout << "1. Safest Driving Area\n";
cout << "2. Lowest Score Drop\n";
cout << "3. Quit" << endl;
cin >> choice;
if (choice == 1)
{
int north, south, east, west, central;
for (int i = 0; i < 5; i++)
{
switch (i)
{
case 0:
north = getNumAccidents("North");
break;
case 1:
south = getNumAccidents("South");
break;
case 2:
east = getNumAccidents("East");
break;
case 3:
west = getNumAccidents("West");
break;
case 4:
central = getNumAccidents("Central");
}
}
findLowest(north, south, east, west, central);
}
return 0;
}
int getNumAccidents(string region)
{
int accidents = 0;
cout << "Please enter the number of accidents for region " << region << " : ";
cin >> accidents;
while (accidents = 0)
{
cout << " The number of accidnts can not be a negative number. Please re-enter accidents: ";
cin >> accidents;
}
return (accidents);
}
void findLowest(int region1, int region2, int region3, int region4, int region5)
{
int lowest = 0;
string region = "";
if (region1 < region2 && region1 < region3 && region1 < region4 && region1 < region5)
{
lowest = region1;
region = "North";
}
else if (region2 < region1 && region2 < region3 && region2 < region4 && region2 < region5)
{
lowest = region2;
region = "South";
}
else if (region3 < region1 && region3 < region2 && region3 < region4 && region3 < region5)
{
lowest = region3;
region = "East";
}
else if (region4 < region1 && region4 < region2 && region4 < region3 && region4 < region5)
{
lowest = region4;
region = "West";
}
else if (region5 < region1 && region5 < region2 && region5 < region3 && region5 < region4)
{
lowest = region5;
region = "Central";
}
cout << "The region with the lowest accidents is: " << region << ". " << endl;
cout << "The total number of accidents in that region was: " << lowest << " . " << endl;
}
|