-
Notifications
You must be signed in to change notification settings - Fork 0
/
SafestDrivingArea.cpp
78 lines (71 loc) · 1.9 KB
/
SafestDrivingArea.cpp
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
//CSC114-651
//Student: Christopher Yonek (700642859)
//Assignment: HW 6 - Determine the safest driving area
//Date: October, 2018
#include "pch.h"
#include <iostream>
#include <conio.h>
#include <string>
using namespace std;
int getNumAccidents(string);
void getLowest(int, int, int, int, int);
int main() {
int totalNorth, totalSouth, totalEast, totalWest, totalCentral;
for (int i = 0; i < 5; i++)
switch (i) {
case 0:
totalNorth = getNumAccidents("North");
break;
case 1:
totalSouth = getNumAccidents("South");
break;
case 2:
totalEast = getNumAccidents("East");
break;
case 3:
totalWest = getNumAccidents("West");
break;
default: totalCentral = getNumAccidents("Central");
break;
}
getLowest(totalNorth, totalSouth, totalEast, totalWest, totalEast);
_getch();
return 0;
}
int getNumAccidents(string location){
int accidents = 0;
std::cout << "Enter the number of accidents for city:\n" << location << " ";
cin >> accidents;
while (accidents <0){
std::cout << "Enter a number greater than 0";
std::cin >> accidents;
}
return accidents;
}
void getLowest(int north, int south, int east, int west, int central){
int lowest = 0;
string location;
if (north < south && north < east && north < west && north < central){
lowest = north;
location = "North";
}
else if (south < north && south < east && south < west && south < central){
lowest = south;
location = "South";
}
else if (east < north && east < south && east < west && east < central)
{
lowest = east;
location = "East";
}
else if (west < north && west < south && west < south && west < central)
{
lowest = west;
location = "West";
}
else {
lowest = central;
location = "Central";
}
std::cout << "The city with least accidents is:\n" << location << "\n The number of accidents in that city is:\n" << lowest;
}