Advertisement
Guest User

Untitled

a guest
Jul 26th, 2017
57
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. int main()
  39. {
  40.     system("Color 17");
  41.     string locationName;
  42.     int north,south,east,west,central,numAccidents;
  43.  
  44.     cout<<"There are 5 locations inside the city.\n";    
  45.                              
  46.         locationName="north:";
  47.         north = getNumAccidents(locationName);
  48.                          
  49.         locationName="south:";
  50.         south = getNumAccidents(locationName);
  51.                        
  52.         locationName="east:";
  53.         east = getNumAccidents(locationName);
  54.                        
  55.         locationName="west:";
  56.         west = getNumAccidents(locationName);
  57.                          
  58.         locationName="central:";
  59.         central = getNumAccidents(locationName);
  60.  
  61.         findLowest(north,south,east,west,central,numAccidents);
  62.            
  63.         cout<<"\n";cout<<"\n";
  64.         cout<<"\n";cout<<"\n";
  65.         system("pause");
  66.         return 0;          
  67.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement