Advertisement
Guest User

Untitled

a guest
Jul 26th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.75 KB | None | 0 0
  1. // SafeDrivingArea.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include"stdafx.h"
  5. #include<iostream>
  6. #include<iomanip>
  7. #include<string>
  8. using namespace std;
  9.  
  10. int getNumAccidents(string regionName)   
  11.     {  
  12.        int numAccidents;
  13.          do
  14.          {
  15.               cout << "Enter the number of accidents for "<<regionName;                
  16.               cin>>numAccidents;
  17.  
  18.           }while (numAccidents < 0);
  19.           return numAccidents;  
  20.     }
  21.  
  22. void findLowest(int north, int south, int east, int west, int central,int &numAccidents)
  23. {
  24.      string locationName;
  25.  
  26.      for (int i = 1; i < numAccidents; i++)
  27.      {      
  28.         if (numAccidents > north){locationName = "north";}
  29.         if (numAccidents > south){locationName = "south";}     
  30.         if (numAccidents > east){locationName = "east";}
  31.         if (numAccidents > west){locationName = "west";}
  32.         if (numAccidents > central){locationName = "central";}
  33.      }
  34.         cout<<"\n";cout<<"\n";
  35.         cout<<"The Safest Area: "<<locationName<<endl;     
  36. }
  37.  
  38.  
  39. int main()
  40. {
  41.     system("Color 17");
  42.     string locationName;
  43.     int north,south,east,west,central,numAccidents;
  44.  
  45.     cout<<"There are 5 locations inside the city.\n";    
  46.                              
  47.         locationName="north:";
  48.         north = getNumAccidents(locationName);
  49.                          
  50.         locationName="south:";
  51.         south = getNumAccidents(locationName);
  52.                        
  53.         locationName="east:";
  54.         east = getNumAccidents(locationName);
  55.                        
  56.         locationName="west:";
  57.         west = getNumAccidents(locationName);
  58.                          
  59.         locationName="central:";
  60.         central = getNumAccidents(locationName);
  61.  
  62.         findLowest(north,south,east,west,central,numAccidents);
  63.            
  64.         cout<<"\n";cout<<"\n";
  65.         cout<<"\n";cout<<"\n";
  66.         system("pause");
  67.         return 0;          
  68.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement